group_data.SpatVector {tidyterra}R Documentation

Grouping metadata for SpatVector objects

Description

This collection of functions accesses data about grouped SpatVector objects in various ways:

See dplyr::group_data().

Usage

## S3 method for class 'SpatVector'
group_data(.data)

## S3 method for class 'SpatVector'
group_keys(.tbl, ...)

## S3 method for class 'SpatVector'
group_indices(.data, ...)

## S3 method for class 'SpatVector'
group_vars(x)

## S3 method for class 'SpatVector'
groups(x)

## S3 method for class 'SpatVector'
group_size(x)

## S3 method for class 'SpatVector'
n_groups(x)

Arguments

.data, .tbl, x

A SpatVector.

...

Use of ... is now deprecated; please use group_by() first instead.

Value

See the description of the function. The results are usually tibbles, lists or vectors. These functions does not return SpatVector objects.

Examples

library(terra)

v <- vect(system.file("extdata/cyl.gpkg", package = "tidyterra"))
v$gr_1 <- rep_len(c("A", "A", "B"), length.out = nrow(v))
v$gr_2 <- rep_len(c("C", "D"), length.out = nrow(v))

# Ungrouped

n_groups(v)

group_vars(v)

group_keys(v)

group_size(v)

groups(v)

group_rows(v)

group_data(v)

group_indices(v)

# Grouped by one var
gv <- group_by(v, gr_1)

n_groups(gv)

group_vars(gv)

group_keys(gv)

group_size(gv)

groups(gv)

group_rows(gv)

group_data(gv)

group_indices(gv)

# Grouped by several vars

gv2 <- group_by(v, gr_1, gr_2)

n_groups(gv2)

group_vars(gv2)

group_keys(gv2)

group_size(gv2)

groups(gv2)

group_rows(gv2)

group_data(gv2)

group_indices(gv2)

[Package tidyterra version 0.7.2 Index]