ref_expand | R Documentation |
For example, a municipality-level reference data.frame might contain three hierarchical columns — country, state, and municipality — but nonetheless only reflect the municipality level in that all rows represent a unique municipality. The lower-resolution levels (state, country) are implied but not explicitly represented as unique rows. If we wish to allow matches to the lower-resolution levels, we need additional rows specific to these levels.
This function takes a reference data.frame with N hierarchical columns, and adds rows for each unique combination of each level that is not currently explicitly represented.
ref_expand(ref, pattern, by, lowest_level = 1L)
ref |
|
pattern |
regex pattern to match the names of the hierarchical columns
in |
by |
vector giving the names of the hierarchical columns in |
lowest_level |
integer representing the lowest-resolution level
(defaults to |
A data.frame
created by expanding ref
to all implied hierarchical levels
# subset example reference df to the admin-2 level
ne_ref_adm2 <- ne_ref[!is.na(ne_ref$adm2),]
# expand back to all levels
ref_expand(ne_ref_adm2, pattern = "adm", lowest_level = 0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.