is_spacetime_cube: Test if a spacetime object is a spacetime cube

View source: R/spacetime-cube-test.R

is_spacetime_cubeR Documentation

Test if a spacetime object is a spacetime cube

Description

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.

Usage

is_spacetime_cube(x, ...)

Arguments

x

a spacetime object

...

unused

Details

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.

Value

A logical scalar.

Validation

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

Examples

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)

sfdep documentation built on Jan. 11, 2023, 9:08 a.m.