Skip to contents

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 SpatVector.

...

<data-masking>

Name-value pairs of functions. The name will be the name of the variable in the result. The value can be a vector of any length.

Unnamed data frame values 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 to group_by(). For details and examples, see ?dplyr_by.

.dissolve

Logical. If TRUE, dissolve borders between aggregated geometries.

Value

A SpatVector.

Methods

Implementation of the generic dplyr::reframe() method.

SpatVector

For grouped inputs, and for 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.

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
#>               ...