View source: R/spacetime-cube-test.R
is_spacetime_cube | R Documentation |
Given an object with class spacetime
, determine if it is a spacetime cube.
If the time-series is is irregular a warning is emitted
(see validate_spacetime()
for more on the restrictions on the time column.
is_spacetime_cube(x, ...)
x |
a spacetime object |
... |
unused |
A spacetime object is a spacetime cube when it contains a regular time-series representation of each geometry. That is, only one observation for at each time period per geography is present.
The number of rows in a spacetime cube is the number of geographies multiplied by the number of time periods. For example if there are 10 locations and 20 time periods, the number of rows must be 200.
A logical scalar.
is_spacetime_cube()
runs a number of checks that to ensure that the provided
object is in fact a spacetime cube. It checks that:
the number of rows is equal to the number of locations multiplied by the number of time periods
each time period has an equal number of observations
each location has an equal number of observations
each combination of time period and location has only one observation
that the time-series is regular
if (requireNamespace("zoo", quietly = TRUE)) {
df_fp <- system.file("extdata", "bos-ecometric.csv", package = "sfdep")
geo_fp <- system.file("extdata", "bos-ecometric.geojson", package = "sfdep")
# read in data
df <- read.csv(
df_fp, colClasses = c("character", "character", "integer", "double", "Date")
)
geo <- sf::st_read(geo_fp)
# Create spacetime object called `bos`
bos <- spacetime(df, geo,
.loc_col = ".region_id",
.time_col = "time_period")
is_spacetime_cube(bos)
is_spacetime_cube(bos[round(runif(1000, 0, nrow(bos))),])
is_spacetime_cube(guerry)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.