View source: R/datawrangling.R
expand_types | R Documentation |
Takes a data frame with a column of type codes
(main type or subtype codes),
and, under certain conditions, adds new rows with codes of the associated
subtypes and main types, respectively.
It allows to do sensible selections and joins with interpreted forms of the
habitatmap_stdized
and watersurfaces_hab
data sources:
habitatmap_terr
,
read_watersurfaces_hab(interpreted = TRUE)
.
If the data frame has one or more grouping variables, by default the
operation is done independently for each group in turn.
expand_types(x, type_var = "type", use_grouping = TRUE, strict = TRUE)
x |
An object of class |
type_var |
A string.
The name of the data frame variable that holds the type codes.
Defaults to |
use_grouping |
Logical.
If the data frame has one or more grouping variables
(class |
strict |
Logical. Apply conditions before expanding subtype codes to main type codes? |
The extra rows in the data frame take the values for other variables
from the rows with which they are associated, based on the
subtype - main type relation.
Type codes in the data frame are verified to comply with the codes from the
types
data source.
A warning is given when they don't.
Main type codes are always expanded with the subtype codes that belong to it.
The applied approach to add main type codes only makes sense assuming that the result is to be confronted with one of the above listed geospatial data sources.
In order to add main type codes based on subtype codes that are present in the type column, specific conditions have to be met:
for 2330: both subtype codes must be present
for 5130: 5130_hei must be present (note that only the main type code occurs in the targeted data sources)
for 6230: 6230_ha, 6230_hmo and 6230_hn must be present (not the rare 6230_hnk)
for 91E0: 91E0_va, 91E0_vm and 91E0_vn must be present (not the rarer 91E0_sf, 91E0_vc and 91E0_vo)
However, it is possible to relax this requirement by setting
strict = FALSE
.
This will add the main type code whenever one of the above required
subtype codes is present.
In all cases no other main type codes are added apart from
2330, 5130, 6230 and 91E0.
This is because the data sources with which the result
is to be matched (see Description) don't contain certain main type codes,
and because it makes no sense in other cases
(rbbkam, rbbzil & 9120 in the habitatmap
do not refer to a
main type but to a non-defined subtype with no specific code).
A data frame, either identical or longer than the input data frame.
read_types
,
read_habitatmap_terr
,
read_watersurfaces_hab
library(dplyr)
x <-
n2khabmon::read_scheme_types() %>%
filter(scheme == "GW_05.1_terr")
expand_types(x)
expand_types(x, strict = FALSE)
x <-
n2khabmon::read_scheme_types() %>%
filter(scheme == "GW_05.1_terr") %>%
group_by(typegroup)
expand_types(x)
expand_types(x, use_grouping = FALSE) # equals above example
x <-
tribble(
~mycode, ~obs,
"2130", 5,
"2190", 45,
"2330_bu", 8,
"2330_dw", 8,
"5130_hei", 7,
"6410_mo", 78,
"6410_ve", 4,
"91E0_vn", 10
)
expand_types(x, type_var = "mycode")
expand_types(x, type_var = "mycode", strict = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.