'tidyverse' methods for sftime
objects. Geometries are sticky, use
as.data.frame
to let dplyr
's own methods drop them. Use
these methods without the .sftime
suffix and after loading the
'tidyverse' package with the generic (or after loading package 'tidyverse').
Usage
inner_join.sftime(x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ...)
left_join.sftime(x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ...)
right_join.sftime(x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ...)
full_join.sftime(x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ...)
semi_join.sftime(x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ...)
anti_join.sftime(x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ...)
filter.sftime(.data, ..., .dots)
arrange.sftime(.data, ..., .dots)
group_by.sftime(.data, ..., add = FALSE)
ungroup.sftime(.data, ...)
rowwise.sftime(.data, ...)
mutate.sftime(.data, ..., .dots)
transmute.sftime(.data, ..., .dots)
select.sftime(.data, ...)
rename.sftime(.data, ...)
slice.sftime(.data, ..., .dots)
summarise.sftime(.data, ..., .dots, do_union = TRUE, is_coverage = FALSE)
summarize.sftime(.data, ..., .dots, do_union = TRUE, is_coverage = FALSE)
distinct.sftime(.data, ..., .keep_all = FALSE)
gather.sftime(
data,
key,
value,
...,
na.rm = FALSE,
convert = FALSE,
factor_key = FALSE
)
pivot_longer.sftime(
data,
cols,
names_to = "name",
names_prefix = NULL,
names_sep = NULL,
names_pattern = NULL,
names_ptypes = NULL,
names_transform = NULL,
names_repair = "check_unique",
values_to = "value",
values_drop_na = FALSE,
values_ptypes = NULL,
values_transform = NULL,
...
)
spread.sftime(
data,
key,
value,
fill = NA,
convert = FALSE,
drop = TRUE,
sep = NULL
)
sample_n.sftime(
tbl,
size,
replace = FALSE,
weight = NULL,
.env = parent.frame()
)
sample_frac.sftime(
tbl,
size = 1,
replace = FALSE,
weight = NULL,
.env = parent.frame()
)
nest.sftime(.data, ...)
unnest.sftime(data, ..., .preserve = NULL)
separate.sftime(
data,
col,
into,
sep = "[^[:alnum:]]+",
remove = TRUE,
convert = FALSE,
extra = "warn",
fill = "warn",
...
)
unite.sftime(data, col, ..., sep = "_", remove = TRUE)
separate_rows.sftime(data, ..., sep = "[^[:alnum:]]+", convert = FALSE)
drop_na.sftime(data, ...)
Arguments
- x
An object of class
sftime
.- y
- by
A join specification created with
join_by()
, or a character vector of variables to join by.If
NULL
, the default,*_join()
will perform a natural join, using all variables in common acrossx
andy
. A message lists the variables so that you can check they're correct; suppress the message by supplyingby
explicitly.To join on different variables between
x
andy
, use ajoin_by()
specification. For example,join_by(a == b)
will matchx$a
toy$b
.To join by multiple variables, use a
join_by()
specification with multiple expressions. For example,join_by(a == b, c == d)
will matchx$a
toy$b
andx$c
toy$d
. If the column names are the same betweenx
andy
, you can shorten this by listing only the variable names, likejoin_by(a, c)
.join_by()
can also be used to perform inequality, rolling, and overlap joins. See the documentation at ?join_by for details on these types of joins.For simple equality joins, you can alternatively specify a character vector of variable names to join by. For example,
by = c("a", "b")
joinsx$a
toy$a
andx$b
toy$b
. If variable names differ betweenx
andy
, use a named character vector likeby = c("x_a" = "y_a", "x_b" = "y_b")
.To perform a cross-join, generating all combinations of
x
andy
, seecross_join()
.- copy
If
x
andy
are not from the same data source, andcopy
isTRUE
, theny
will be copied into the same src asx
. This allows you to join tables across srcs, but it is a potentially expensive operation so you must opt into it.- suffix
If there are non-joined duplicate variables in
x
andy
, these suffixes will be added to the output to disambiguate them. Should be a character vector of length 2.- ...
other arguments
- .data
An object of class
stime
.- .dots
see corresponding function in package
dplyr
- add
see corresponding function in dplyr
- do_union
logical; in case
summary
does not create a geometry column, should geometries be created by unioning using st_union, or simply by combining using st_combine? Using st_union resolves internal boundaries, but in case of unioning points, this will likely change the order of the points; see Details.- is_coverage
logical; if
do_union
isTRUE
, use an optimized algorithm for features that form a polygonal coverage (have no overlaps)- .keep_all
see corresponding function in dplyr
- data
see original function docs
- key
see original function docs
- value
see original function docs
- na.rm
see original function docs
- convert
see separate_rows
- factor_key
see original function docs
- cols
see original function docs
- names_to
see original function docs
- names_prefix
see original function docs
- names_sep
see original function docs
- names_pattern
see original function docs
- names_ptypes
see original function docs
- names_transform
see original function docs
- names_repair
see original function docs
- values_to
see original function docs
- values_drop_na
see original function docs
- values_ptypes
see original function docs
- values_transform
see original function docs
- fill
see original function docs
- drop
see original function docs
- sep
see separate_rows
- tbl
see original function docs
- size
see original function docs
- replace
see original function docs
- weight
see original function docs
- .env
see original function docs
- .preserve
see unnest
- col
see separate
- into
see separate
- remove
see separate
- extra
see separate
Value
For
_join
methods: An object of classsftime
representing the joining result ofx
andy
. Seemutate-joins
.For
filter
: Seefilter
.For
arrange
: Seearrange
.For
group_by
andungroup
: A groupedsftime
object. Seearrange
.For
rowwise
: Ansftime
object. Seerowwise
.For
mutate
andtransmute
: Seemutate
.For
select
: Seeselect
. If the active time column is not explicitly selected, asf
object is returned.For
rename
: Seerename
.For
slice
: Seeslice
.For
summarize
andsummarise
: Seesummarise
.For
distinct
: Seedistinct
.For
gather
: Seegather
.
Examples
g1 <- st_sfc(st_point(1:2), st_point(c(5, 8)), st_point(c(2, 9)))
x1 <- st_sftime(a = 1:3, geometry = g1, time = Sys.time())
g2 <- st_sfc(st_point(c(4, 6)), st_point(c(4, 6)), st_point(c(4, 6)))
x2 <- st_sftime(a = 2:4, geometry = g2, time = Sys.time())
library(dplyr)
## inner_join
inner_join(x1, as.data.frame(x2), by = "a") # note: the active time column is
#> Spatiotemporal feature collection with 2 features and 2 fields
#> Active geometry column: geometry.x
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 2 ymin: 8 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> a time.y geometry.x geometry.y time.x
#> 1 2 2024-09-13 09:15:21 POINT (5 8) POINT (4 6) 2024-09-13 09:15:21
#> 2 3 2024-09-13 09:15:21 POINT (2 9) POINT (4 6) 2024-09-13 09:15:21
# time.x and the active geometry column geometry.x
inner_join(x2, as.data.frame(x1), by = "a")
#> Spatiotemporal feature collection with 2 features and 2 fields
#> Active geometry column: geometry.x
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 4 ymin: 6 xmax: 4 ymax: 6
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.396825 to 2024-09-13 09:15:21.396825.
#> a time.y geometry.x geometry.y time.x
#> 1 2 2024-09-13 09:15:21 POINT (4 6) POINT (5 8) 2024-09-13 09:15:21
#> 2 3 2024-09-13 09:15:21 POINT (4 6) POINT (2 9) 2024-09-13 09:15:21
## left_join
left_join(x1, as.data.frame(x2), by = "a")
#> Spatiotemporal feature collection with 3 features and 2 fields
#> Active geometry column: geometry.x
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> a time.y geometry.x geometry.y time.x
#> 1 1 <NA> POINT (1 2) POINT EMPTY 2024-09-13 09:15:21
#> 2 2 2024-09-13 09:15:21 POINT (5 8) POINT (4 6) 2024-09-13 09:15:21
#> 3 3 2024-09-13 09:15:21 POINT (2 9) POINT (4 6) 2024-09-13 09:15:21
left_join(x2, as.data.frame(x1), by = "a")
#> Spatiotemporal feature collection with 3 features and 2 fields
#> Active geometry column: geometry.x
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 4 ymin: 6 xmax: 4 ymax: 6
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.396825 to 2024-09-13 09:15:21.396825.
#> a time.y geometry.x geometry.y time.x
#> 1 2 2024-09-13 09:15:21 POINT (4 6) POINT (5 8) 2024-09-13 09:15:21
#> 2 3 2024-09-13 09:15:21 POINT (4 6) POINT (2 9) 2024-09-13 09:15:21
#> 3 4 <NA> POINT (4 6) POINT EMPTY 2024-09-13 09:15:21
## right_join
right_join(x1, as.data.frame(x2), by = "a")
#> Spatiotemporal feature collection with 3 features and 2 fields
#> Active geometry column: geometry.x (with 1 geometry empty)
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 2 ymin: 8 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> a time.y geometry.x geometry.y time.x
#> 1 2 2024-09-13 09:15:21 POINT (5 8) POINT (4 6) 2024-09-13 09:15:21
#> 2 3 2024-09-13 09:15:21 POINT (2 9) POINT (4 6) 2024-09-13 09:15:21
#> 3 4 2024-09-13 09:15:21 POINT EMPTY POINT (4 6) <NA>
right_join(x2, as.data.frame(x1), by = "a")
#> Spatiotemporal feature collection with 3 features and 2 fields
#> Active geometry column: geometry.x (with 1 geometry empty)
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 4 ymin: 6 xmax: 4 ymax: 6
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.396825 to 2024-09-13 09:15:21.396825.
#> a time.y geometry.x geometry.y time.x
#> 1 2 2024-09-13 09:15:21 POINT (4 6) POINT (5 8) 2024-09-13 09:15:21
#> 2 3 2024-09-13 09:15:21 POINT (4 6) POINT (2 9) 2024-09-13 09:15:21
#> 3 1 2024-09-13 09:15:21 POINT EMPTY POINT (1 2) <NA>
## full_join
full_join(x1, as.data.frame(x2), by = "a")
#> Spatiotemporal feature collection with 4 features and 2 fields
#> Active geometry column: geometry.x (with 1 geometry empty)
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> a time.y geometry.x geometry.y time.x
#> 1 1 <NA> POINT (1 2) POINT EMPTY 2024-09-13 09:15:21
#> 2 2 2024-09-13 09:15:21 POINT (5 8) POINT (4 6) 2024-09-13 09:15:21
#> 3 3 2024-09-13 09:15:21 POINT (2 9) POINT (4 6) 2024-09-13 09:15:21
#> 4 4 2024-09-13 09:15:21 POINT EMPTY POINT (4 6) <NA>
full_join(x2, as.data.frame(x1), by = "a")
#> Spatiotemporal feature collection with 4 features and 2 fields
#> Active geometry column: geometry.x (with 1 geometry empty)
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 4 ymin: 6 xmax: 4 ymax: 6
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.396825 to 2024-09-13 09:15:21.396825.
#> a time.y geometry.x geometry.y time.x
#> 1 2 2024-09-13 09:15:21 POINT (4 6) POINT (5 8) 2024-09-13 09:15:21
#> 2 3 2024-09-13 09:15:21 POINT (4 6) POINT (2 9) 2024-09-13 09:15:21
#> 3 4 <NA> POINT (4 6) POINT EMPTY 2024-09-13 09:15:21
#> 4 1 2024-09-13 09:15:21 POINT EMPTY POINT (1 2) <NA>
## semi_join
semi_join(x1, as.data.frame(x2), by = "a")
#> Spatiotemporal feature collection with 2 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 2 ymin: 8 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> a geometry time
#> 1 2 POINT (5 8) 2024-09-13 09:15:21
#> 2 3 POINT (2 9) 2024-09-13 09:15:21
semi_join(x2, as.data.frame(x1), by = "a")
#> Spatiotemporal feature collection with 2 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 4 ymin: 6 xmax: 4 ymax: 6
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.396825 to 2024-09-13 09:15:21.396825.
#> a geometry time
#> 1 2 POINT (4 6) 2024-09-13 09:15:21
#> 2 3 POINT (4 6) 2024-09-13 09:15:21
## anti_join
anti_join(x1, as.data.frame(x2), by = "a")
#> Spatiotemporal feature collection with 1 feature and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 1 ymax: 2
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Representing 2024-09-13 09:15:21.393653.
#> a geometry time
#> 1 1 POINT (1 2) 2024-09-13 09:15:21
anti_join(x2, as.data.frame(x1), by = "a")
#> Spatiotemporal feature collection with 1 feature and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 4 ymin: 6 xmax: 4 ymax: 6
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Representing 2024-09-13 09:15:21.396825.
#> a geometry time
#> 1 4 POINT (4 6) 2024-09-13 09:15:21
## filter
filter(x1, a <= 2)
#> Spatiotemporal feature collection with 2 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 8
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> a geometry time
#> 1 1 POINT (1 2) 2024-09-13 09:15:21
#> 2 2 POINT (5 8) 2024-09-13 09:15:21
## arrange
arrange(x1, dplyr::desc(a))
#> Spatiotemporal feature collection with 3 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> a time geometry
#> 1 3 2024-09-13 09:15:21 POINT (2 9)
#> 2 2 2024-09-13 09:15:21 POINT (5 8)
#> 3 1 2024-09-13 09:15:21 POINT (1 2)
## group_by
group_by(x1, time)
#> Spatiotemporal feature collection with 3 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> # A tibble: 3 × 3
#> # Groups: time [1]
#> a geometry time
#> * <int> <POINT> <dttm>
#> 1 1 (1 2) 2024-09-13 09:15:21
#> 2 2 (5 8) 2024-09-13 09:15:21
#> 3 3 (2 9) 2024-09-13 09:15:21
## ungroup
ungroup(group_by(x1, time))
#> Spatiotemporal feature collection with 3 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> # A tibble: 3 × 3
#> a geometry time
#> * <int> <POINT> <dttm>
#> 1 1 (1 2) 2024-09-13 09:15:21
#> 2 2 (5 8) 2024-09-13 09:15:21
#> 3 3 (2 9) 2024-09-13 09:15:21
## rowwise
x1 %>%
mutate(a1 = 5:7) %>%
rowwise() %>%
mutate(a2 = mean(a, a1))
#> Spatiotemporal feature collection with 3 features and 3 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> # A tibble: 3 × 5
#> # Rowwise:
#> a geometry time a1 a2
#> * <int> <POINT> <dttm> <int> <int>
#> 1 1 (1 2) 2024-09-13 09:15:21 5 1
#> 2 2 (5 8) 2024-09-13 09:15:21 6 2
#> 3 3 (2 9) 2024-09-13 09:15:21 7 3
## mutate
x1 %>%
mutate(a1 = 5:7)
#> Spatiotemporal feature collection with 3 features and 2 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> a geometry time a1
#> 1 1 POINT (1 2) 2024-09-13 09:15:21 5
#> 2 2 POINT (5 8) 2024-09-13 09:15:21 6
#> 3 3 POINT (2 9) 2024-09-13 09:15:21 7
## transmute
x1 %>%
transmute(a1 = 5:7)
#> Simple feature collection with 3 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> a1 geometry
#> 1 5 POINT (1 2)
#> 2 6 POINT (5 8)
#> 3 7 POINT (2 9)
## select
x1 %>%
select(-time) %>%
select(geometry)
#> Simple feature collection with 3 features and 0 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> geometry
#> 1 POINT (1 2)
#> 2 POINT (5 8)
#> 3 POINT (2 9)
## rename
x1 %>%
rename(a1 = a)
#> Spatiotemporal feature collection with 3 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> a1 time geometry
#> 1 1 2024-09-13 09:15:21 POINT (1 2)
#> 2 2 2024-09-13 09:15:21 POINT (5 8)
#> 3 3 2024-09-13 09:15:21 POINT (2 9)
## slice
x1 %>%
slice(1:2)
#> Spatiotemporal feature collection with 2 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 8
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> a time geometry
#> 1 1 2024-09-13 09:15:21 POINT (1 2)
#> 2 2 2024-09-13 09:15:21 POINT (5 8)
## summarise
x1 %>%
summarise(time = mean(time))
#> Spatiotemporal feature collection with 1 feature and 0 fields
#> Geometry type: MULTIPOINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Representing 2024-09-13 09:15:21.393653.
#> time geometry
#> 1 2024-09-13 09:15:21 MULTIPOINT ((1 2), (2 9), (...
x1 %>%
summarize(time = mean(time))
#> Spatiotemporal feature collection with 1 feature and 0 fields
#> Geometry type: MULTIPOINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Representing 2024-09-13 09:15:21.393653.
#> time geometry
#> 1 2024-09-13 09:15:21 MULTIPOINT ((1 2), (2 9), (...
## distinct
x1 %>%
distinct(geometry)
#> Simple feature collection with 3 features and 0 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> geometry
#> 1 POINT (1 2)
#> 2 POINT (5 8)
#> 3 POINT (2 9)
## gather
library(tidyr)
x1 %>%
mutate(a1 = 5:7) %>%
gather(key = "variable", value = "value", a, a1)
#> Spatiotemporal feature collection with 6 features and 2 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> time key value geometry
#> 1 2024-09-13 09:15:21 a 1 POINT (1 2)
#> 2 2024-09-13 09:15:21 a 2 POINT (5 8)
#> 3 2024-09-13 09:15:21 a 3 POINT (2 9)
#> 4 2024-09-13 09:15:21 a1 5 POINT (1 2)
#> 5 2024-09-13 09:15:21 a1 6 POINT (5 8)
#> 6 2024-09-13 09:15:21 a1 7 POINT (2 9)
## pivot_longer
x1 %>%
mutate(a1 = 5:7) %>%
pivot_longer(cols = c("a", "a1"), names_to = "variable", values_to = "value")
#> Spatiotemporal feature collection with 6 features and 2 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> # A tibble: 6 × 4
#> geometry time variable value
#> * <POINT> <dttm> <chr> <int>
#> 1 (1 2) 2024-09-13 09:15:21 a 1
#> 2 (1 2) 2024-09-13 09:15:21 a1 5
#> 3 (5 8) 2024-09-13 09:15:21 a 2
#> 4 (5 8) 2024-09-13 09:15:21 a1 6
#> 5 (2 9) 2024-09-13 09:15:21 a 3
#> 6 (2 9) 2024-09-13 09:15:21 a1 7
## spread
x1 %>%
mutate(a1 = 5:7) %>%
gather(key = "variable", value = "value", a, a1) %>%
spread(key = "variable", value = "value")
#> Spatiotemporal feature collection with 3 features and 2 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> time a a1 geometry
#> 1 2024-09-13 09:15:21 1 5 POINT (1 2)
#> 2 2024-09-13 09:15:21 2 6 POINT (5 8)
#> 3 2024-09-13 09:15:21 3 7 POINT (2 9)
## sample_n
set.seed(234)
x1 %>%
sample_n(size = 10, replace = TRUE)
#> Spatiotemporal feature collection with 10 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> a time geometry
#> 1 1 2024-09-13 09:15:21 POINT (1 2)
#> 2 3 2024-09-13 09:15:21 POINT (2 9)
#> 3 2 2024-09-13 09:15:21 POINT (5 8)
#> 4 2 2024-09-13 09:15:21 POINT (5 8)
#> 5 2 2024-09-13 09:15:21 POINT (5 8)
#> 6 2 2024-09-13 09:15:21 POINT (5 8)
#> 7 1 2024-09-13 09:15:21 POINT (1 2)
#> 8 1 2024-09-13 09:15:21 POINT (1 2)
#> 9 3 2024-09-13 09:15:21 POINT (2 9)
#> 10 2 2024-09-13 09:15:21 POINT (5 8)
## sample_frac
x1 %>%
sample_frac(size = 10, replace = TRUE) %>%
sample_frac(size = 0.1, replace = FALSE)
#> Spatiotemporal feature collection with 3 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 2 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> a time geometry
#> 1 1 2024-09-13 09:15:21 POINT (1 2)
#> 2 1 2024-09-13 09:15:21 POINT (1 2)
#> 3 3 2024-09-13 09:15:21 POINT (2 9)
## nest
x1 %>%
nest(a1 = -time)
#> time a1
#> 1 2024-09-13 09:15:21 1, 2, 3, 1, 2, 5, 8, 2, 9
## unnest
x1 %>%
mutate(a1 = list(1, c(1, 2), 5)) %>%
unnest(a1)
#> Spatiotemporal feature collection with 4 features and 2 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> # A tibble: 4 × 4
#> a geometry time a1
#> * <int> <POINT> <dttm> <dbl>
#> 1 1 (1 2) 2024-09-13 09:15:21 1
#> 2 2 (5 8) 2024-09-13 09:15:21 1
#> 3 2 (5 8) 2024-09-13 09:15:21 2
#> 4 3 (2 9) 2024-09-13 09:15:21 5
## separate
x1 %>%
mutate(x = c(NA, "a.b", "a.d")) %>%
separate(x, c("A", "B"))
#> Spatiotemporal feature collection with 3 features and 3 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> a time A B geometry
#> 1 1 2024-09-13 09:15:21 <NA> <NA> POINT (1 2)
#> 2 2 2024-09-13 09:15:21 a b POINT (5 8)
#> 3 3 2024-09-13 09:15:21 a d POINT (2 9)
## unite
x1 %>%
mutate(x = c(NA, "a.b", "a.d")) %>%
separate(x, c("A", "B")) %>%
unite(x, c("A", "B"))
#> Spatiotemporal feature collection with 3 features and 2 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> a time col geometry
#> 1 1 2024-09-13 09:15:21 NA_NA POINT (1 2)
#> 2 2 2024-09-13 09:15:21 a_b POINT (5 8)
#> 3 3 2024-09-13 09:15:21 a_d POINT (2 9)
## separate_rows
x1 %>%
mutate(z = c("1", "2,3,4", "5,6")) %>%
separate_rows(z, convert = TRUE)
#> Spatiotemporal feature collection with 6 features and 2 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> # A tibble: 6 × 4
#> a geometry time z
#> * <int> <POINT> <dttm> <int>
#> 1 1 (1 2) 2024-09-13 09:15:21 1
#> 2 2 (5 8) 2024-09-13 09:15:21 2
#> 3 2 (5 8) 2024-09-13 09:15:21 3
#> 4 2 (5 8) 2024-09-13 09:15:21 4
#> 5 3 (2 9) 2024-09-13 09:15:21 5
#> 6 3 (2 9) 2024-09-13 09:15:21 6
## drop_na
x1 %>%
mutate(z = c(1, 2, NA)) %>%
drop_na(z)
#> Spatiotemporal feature collection with 2 features and 2 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 5 ymax: 8
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> a time z geometry
#> 1 1 2024-09-13 09:15:21 1 POINT (1 2)
#> 2 2 2024-09-13 09:15:21 2 POINT (5 8)
x1 %>%
mutate(z = c(1, NA, NA)) %>%
drop_na(z)
#> Spatiotemporal feature collection with 1 feature and 2 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 1 ymin: 2 xmax: 1 ymax: 2
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Representing 2024-09-13 09:15:21.393653.
#> a time z geometry
#> 1 1 2024-09-13 09:15:21 1 POINT (1 2)
x1 %>%
mutate(time = replace(time, 1, NA)) %>%
drop_na(time)
#> Spatiotemporal feature collection with 2 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 2 ymin: 8 xmax: 5 ymax: 9
#> CRS: NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2024-09-13 09:15:21.393653 to 2024-09-13 09:15:21.393653.
#> a time geometry
#> 1 2 2024-09-13 09:15:21 POINT (5 8)
#> 2 3 2024-09-13 09:15:21 POINT (2 9)