Learn R Programming

tidyterra (version 1.3.0)

group_nest.SpatVector: Nest grouped SpatVector rows

Description

[Experimental]

group_nest() and nest_by() create tibbles with list-columns containing SpatVector objects.

Usage

# S3 method for SpatVector
group_nest(.tbl, ..., .key = "data", keep = FALSE)

# S3 method for SpatVector nest_by(.data, ..., .key = "data", .keep = FALSE)

Value

A tibble with a list-column of SpatVector objects.

Arguments

.tbl, .data

A SpatVector.

...

Grouping specification, forwarded to group_by()

.key

the name of the list column

keep, .keep

Should the grouping columns be kept in the list column.

<a href="https://CRAN.R-project.org/package=terra"><span class="pkg">terra</span></a> equivalent

terra::svc().

Methods

Implementation of the generic dplyr::group_nest() method family for SpatVector objects.

The nested list-column contains SpatVector objects, preserving the geometries for each group.

See Also

dplyr::group_nest(), dplyr::nest_by(), nest.SpatVector(), terra::svc().

Other dplyr grouping methods: group_by.SpatVector(), group_data.SpatVector(), group_map.SpatVector(), group_split.SpatVector(), group_trim.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))

group_nest(v, grp)

nest_by(v, grp)

# Convert to a named SpatVectorCollection.
nested <- group_nest(v, grp)

sv <- pull(nested, data)
names(sv) <- pull(nested, grp)

terra::svc(sv)

Run the code above in your browser using DataLab