SpatVector attribute combinationsexpand() returns a tibble with all combinations of selected attributes.
It does not return a SpatVector because newly created combinations do not
have a well-defined geometry. Use complete.SpatVector() when empty
geometries should be added explicitly.
# S3 method for SpatVector
expand(data, ..., .name_repair = "check_unique")A tibble.
A SpatVector.
<data-masking> Specification of columns
to expand or complete. Columns can be atomic vectors or lists.
To find all unique combinations of x, y and z, including those not
present in the data, supply each variable as a separate argument:
expand(df, x, y, z) or complete(df, x, y, z).
To find only the combinations that occur in the
data, use nesting: expand(df, nesting(x, y, z)).
You can combine the two forms. For example,
expand(df, nesting(school_id, student_id), date) would produce
a row for each present school-student combination for all possible
dates.
When used with factors, expand() and complete() use the full set of
levels, not just those that appear in the data. If you want to use only the
values seen in the data, use forcats::fct_drop().
When used with continuous variables, you may need to fill in values
that do not appear in the data: to do so use expressions like
year = 2010:2020 or year = full_seq(year,1).
One of "check_unique", "unique", "universal",
"minimal", "unique_quiet", or "universal_quiet". See vec_as_names()
for the meaning of these options.
Implementation of the generic tidyr::expand() method for SpatVector
objects.
The output is a tibble with attribute combinations. Geometry is not preserved because new combinations do not have a well-defined geometry.
tidyr::expand(), complete.SpatVector().
Other tidyr verbs for handling missing values:
complete.SpatVector(),
drop_na.Spat,
fill.SpatVector(),
replace_na.Spat
v <- terra::vect(system.file("extdata/cyl.gpkg", package = "tidyterra"))
v$grp <- rep(c("A", "B"), length.out = nrow(v))
expand(v, grp, cpro)
Run the code above in your browser using DataLab