Learn R Programming

tidyterra (version 1.3.0)

uncount.SpatVector: Duplicate SpatVector rows

Description

uncount() duplicates rows according to a weighting variable.

Usage

# S3 method for SpatVector
uncount(data, weights, ..., .remove = TRUE, .id = NULL)

Value

A SpatVector object.

Arguments

data

A SpatVector.

weights

A vector of weights. Evaluated in the context of data; supports quasiquotation.

...

Additional arguments passed on to methods.

.remove

If TRUE, and weights is the name of a column in data, then this column is removed.

.id

Supply a string to create a new variable which gives a unique identifier for each created row.

Methods

Implementation of the generic tidyr::uncount() method for SpatVector objects.

Each duplicated row keeps the input geometry.

See Also

Examples

Run this code
library(tidyr)

v <- terra::vect(system.file("extdata/cyl.gpkg", package = "tidyterra"))
v$copies <- rep_len(1:2, nrow(v))

uncount(v, copies)

Run the code above in your browser using DataLab