uncount() duplicates rows according to a weighting variable.
Usage
# S3 method for class 'SpatVector'
uncount(data, weights, ..., .remove = TRUE, .id = NULL)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, andweightsis the name of a column indata, 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.
Examples
library(tidyr)
v <- terra::vect(system.file("extdata/cyl.gpkg", package = "tidyterra"))
v$copies <- rep_len(1:2, nrow(v))
uncount(v, copies)
#> class : SpatVector
#> geometry : polygons
#> dimensions : 13, 3 (geometries, attributes)
#> extent : 2892687, 3341372, 2017622, 2361600 (xmin, xmax, ymin, ymax)
#> coord. ref. : ETRS89-extended / LAEA Europe (EPSG:3035)
#> names : iso2 cpro name
#> type : <chr> <chr> <chr>
#> values : ES-AV 05 Avila
#> ES-BU 09 Burgos
#> ES-BU 09 Burgos
#> ...
