Learn R Programming

tidyterra (version 1.3.0)

group_split.SpatVector: Split SpatVector by groups

Description

[Experimental]

group_split() works like base::split() but:

  • It uses the grouping structure from group_by.SpatVector() and therefore is subject to the data mask.

  • It does not name the elements of the list based on the grouping as this only works well for a single character grouping variable. Instead, use group_keys.SpatVector() to access a data frame that defines the groups.

See dplyr::group_split() for more information.

Usage

# S3 method for SpatVector
group_split(.tbl, ..., .keep = TRUE)

Value

A list of SpatVector objects. Each SpatVector contains the rows of .tbl for the associated group and all columns. When .keep = TRUE, the output includes the grouping variables.

Arguments

.tbl

A SpatVector object. See Methods.

...

If .tbl is an ungrouped SpatVector, a grouping specification, forwarded to group_by.SpatVector().

.keep

Should the grouping columns be kept?

Lifecycle

group_split() is not stable because you can achieve very similar results by manipulating the nested column returned from nest(.by =). That also retains the group keys all within a single data structure. group_split() may be deprecated in the future.

<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_split() method for SpatVector objects.

Details

See Details on dplyr::group_split().

See Also

dplyr::group_split(), terra::svc().

Other dplyr grouping methods: group_by.SpatVector(), group_data.SpatVector(), group_map.SpatVector(), group_nest.SpatVector(), group_trim.SpatVector()

Examples

Run this code
v <- terra::vect(system.file("extdata/cyl.gpkg", package = "tidyterra"))

v$group <- rep(c("A", "B", "C"), 3)

v |>
  group_by(group) |>
  group_split()

# Coerce the result to a SpatVectorCollection.
v |>
  group_by(group) |>
  group_split() |>
  terra::svc()

Run the code above in your browser using DataLab