Learn R Programming

tidyterra (version 1.3.0)

reframe.SpatVector: Reframe each group of a SpatVector

Description

[Experimental]

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 SpatVector
reframe(.data, ..., .by = NULL, .dissolve = TRUE)

Value

A SpatVector.

Arguments

.data

A SpatVector created with terra::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(), or sum(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 to group_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

dplyr::reframe().

Other dplyr verbs that operate on groups of rows: count.SpatVector(), group_by.SpatVector(), rowwise.SpatVector(), summarise.SpatVector()

Examples

Run this code
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)

v |>
  rowwise() |>
  reframe(value = 1:2)

Run the code above in your browser using DataLab