View source: R/spacetime-methods.R
as_sf | R Documentation |
spacetime
and sf
classesCast between spacetime
and sf
classes
Convert sf object to spacetime
as_sf(x, ...)
as_spacetime(x, .loc_col, .time_col, ...)
## S3 method for class 'sf'
as_spacetime(x, .loc_col, .time_col, ...)
x |
for |
... |
arguments passed to merge. |
.loc_col |
the quoted name of the column containing unique location identifiers. |
.time_col |
the quoted name of the column containing time periods. |
For as_spacetime()
returns a spacetime object. For as_sf()
, an sf object.
if (require(dplyr, 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")
as_sf(bos)
if (require("dplyr", quietly=TRUE)) {
as_spacetime(as_sf(bos) , ".region_id", "year")
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.