reframe() can return any number of rows per group. The geometry of each
group is aggregated and repeated for each row created for that group.
Usage
# S3 method for class 'SpatVector'
reframe(.data, ..., .by = NULL, .dissolve = TRUE)Arguments
- .data
A
SpatVectorcreated withterra::vect().- ...
<
data-masking> Name-value pairs of summary functions. The name will be the name of the variable in the result.The value can be:
A vector of length 1, e.g.
min(x),n(), orsum(is.na(y)).A data frame with 1 row, to add multiple columns from a single expression.
- .by
<
tidy-select> Optionally, a selection of columns to group by for just this operation, functioning as an alternative togroup_by(). For details and examples, see ?dplyr_by.- .dissolve
Logical. If
TRUE, dissolve borders between aggregated geometries.
Methods
Implementation of the generic dplyr::reframe() method for
SpatVector objects.
For grouped inputs and calls using .by, geometries are aggregated per
group. If a group produces more than one row, the aggregated group geometry
is repeated for each output row.
See also
Other dplyr verbs that operate on groups of rows:
count.SpatVector(),
group_by.SpatVector(),
rowwise.SpatVector(),
summarise.SpatVector()
Examples
v <- terra::vect(system.file("extdata/cyl.gpkg", package = "tidyterra"))
v$grp <- rep(c("A", "B"), length.out = nrow(v))
v |>
reframe(value = c(min(as.double(cpro)), max(as.double(cpro))), .by = grp)
#> class : SpatVector
#> geometry : polygons
#> dimensions : 4, 2 (geometries, attributes)
#> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax)
#> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035)
#> names : grp value
#> type : <chr> <num>
#> values : A 5
#> A 49
#> B 9
#> ...
v |>
rowwise() |>
reframe(value = 1:2)
#> class : SpatVector
#> geometry : polygons
#> dimensions : 18, 1 (geometries, attributes)
#> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax)
#> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035)
#> names : value
#> type : <int>
#> values : 1
#> 2
#> 1
#> ...
