Resolve culture specifications to their lowest hierarchical level
Source:R/resolve_cultures.R
resolve_cultures.Rd
Resolves culture levels in a dataset to their lowest hierarchical level (leaf nodes)
using a parent-child relationship dataset derived from a culture tree using
the German culture names. Only German culture names are supported.
If no match is found, the function assigns NA
to the leaf_culture_de
column.
If correct_culture_names
is set to TRUE
, the function corrects variations in
the naming of aggregated culture groups with "allg.".
Usage
resolve_cultures(
dataset,
srppp,
culture_column = "culture_de",
correct_culture_names = TRUE
)
Arguments
- dataset
A data frame or tibble containing the data to be processed. It should include a column that represents the culture information to be resolved.
- srppp
An srppp_dm object. From this object the relations from each culture to the leaf cultures (lowest level in the hierarchical tree) are used, which are stored as attribute 'culture_leaf_df' of the culture tree, which is itself stored as an attribute of the object.
- culture_column
(Optional) A character string specifying the column in the dataset that contains the culture information to be resolved. Defaults to
"culture_de"
.- correct_culture_names
If this argument is set to
TRUE
, the following corrections will be applied: In theculture_tree
, and consequently in theculture_leaf_df
, there are variations in the naming of aggregated culture groups with "allg.". For example, both "Obstbau allg." and "allg. Obstbau" exist. However, information about the leaf nodes is only available in the culture groups that start with "allg. ...". This will be adjusted.
Value
A data frame or tibble with the same structure as the input
dataset
, but with an additional column "leaf_culture_de"
that contains
the resolved leaf culture levels.
Details
The resolve_cultures
function processes the input dataset as follows
Leaf Node Resolution: The cultures in the specified column of the dataset are resolved to their
lowest hierarchical level (leaf nodes) based on the culture_leaf_df
mapping.
The result is an expanded dataset that includes an additional column (leaf_culture_de
) containing
the resolved cultures at their lowest level.
Examples
# \donttest{
example_dataset_1 <- data.frame(
substance_de = c("Spirotetramat", "Spirotetramat", "Spirotetramat", "Spirotetramat"),
pNbr = c(7839, 7839, 7839, 7839),
use_nr = c(5, 7, 18, 22),
application_area_de = c("Obstbau", "Obstbau", "Obstbau", "Obstbau"),
culture_de = c("Birne", "Kirsche", "Steinobst", "Kernobst"),
pest_de = c("Birnblattsauger", "Kirschenfliege", "Blattläuse (Röhrenläuse)", "Spinnmilben")
)
example_dataset_2 <- data.frame(
substance_de = c("Spirotetramat", "Spirotetramat", "Spirotetramat", "Spirotetramat"),
pNbr = c(7839, 7839, 7839, 7839),
use_nr = c(5, 7, 18, 22),
application_area_de = c("Obstbau", "Obstbau", "Obstbau", "Obstbau"),
culture_de = c("Birne", "Kirschen", "Steinobst", "Obstbau allg."),
pest_de = c("Birnblattsauger", "Kirschenfliege", "Blattläuse (Röhrenläuse)", "Spinnmilben")
)
example_dataset_3 <- data.frame(
substance_de = c("Pirimicarb"),
pNbr = c(2210),
use_nr = c(3),
application_area_de = c("Feldbau"),
culture_de = c("Getreide"),
pest_de = c("Blattläuse (Röhrenläuse)")
)
library(srppp)
current_register <- srppp_dm()
result1 <- resolve_cultures(example_dataset_1, current_register,
correct_culture_names = FALSE)
print(result1)
#> substance_de pNbr use_nr application_area_de culture_de
#> 1 Spirotetramat 7839 5 Obstbau Birne
#> 2 Spirotetramat 7839 7 Obstbau Kirsche
#> 3 Spirotetramat 7839 18 Obstbau Steinobst
#> 4 Spirotetramat 7839 18 Obstbau Steinobst
#> 5 Spirotetramat 7839 18 Obstbau Steinobst
#> 6 Spirotetramat 7839 18 Obstbau Steinobst
#> 7 Spirotetramat 7839 18 Obstbau Steinobst
#> 8 Spirotetramat 7839 22 Obstbau Kernobst
#> 9 Spirotetramat 7839 22 Obstbau Kernobst
#> 10 Spirotetramat 7839 22 Obstbau Kernobst
#> pest_de leaf_culture_de
#> 1 Birnblattsauger Birne
#> 2 Kirschenfliege Kirsche
#> 3 Blattläuse (Röhrenläuse) Aprikose
#> 4 Blattläuse (Röhrenläuse) Kirsche
#> 5 Blattläuse (Röhrenläuse) Pfirsich / Nektarine
#> 6 Blattläuse (Röhrenläuse) Pflaume
#> 7 Blattläuse (Röhrenläuse) Zwetschge
#> 8 Spinnmilben Apfel
#> 9 Spinnmilben Quitte
#> 10 Spinnmilben Birne
result2 <- resolve_cultures(example_dataset_2, current_register,
correct_culture_names = TRUE)
print(result2)
#> substance_de pNbr use_nr application_area_de culture_de
#> 1 Spirotetramat 7839 5 Obstbau Birne
#> 2 Spirotetramat 7839 7 Obstbau Kirschen
#> 3 Spirotetramat 7839 18 Obstbau Steinobst
#> 4 Spirotetramat 7839 18 Obstbau Steinobst
#> 5 Spirotetramat 7839 18 Obstbau Steinobst
#> 6 Spirotetramat 7839 18 Obstbau Steinobst
#> 7 Spirotetramat 7839 18 Obstbau Steinobst
#> 8 Spirotetramat 7839 22 Obstbau allg. Obstbau
#> 9 Spirotetramat 7839 22 Obstbau allg. Obstbau
#> 10 Spirotetramat 7839 22 Obstbau allg. Obstbau
#> 11 Spirotetramat 7839 22 Obstbau allg. Obstbau
#> 12 Spirotetramat 7839 22 Obstbau allg. Obstbau
#> 13 Spirotetramat 7839 22 Obstbau allg. Obstbau
#> 14 Spirotetramat 7839 22 Obstbau allg. Obstbau
#> 15 Spirotetramat 7839 22 Obstbau allg. Obstbau
#> 16 Spirotetramat 7839 22 Obstbau allg. Obstbau
#> 17 Spirotetramat 7839 22 Obstbau allg. Obstbau
#> pest_de leaf_culture_de
#> 1 Birnblattsauger Birne
#> 2 Kirschenfliege <NA>
#> 3 Blattläuse (Röhrenläuse) Aprikose
#> 4 Blattläuse (Röhrenläuse) Kirsche
#> 5 Blattläuse (Röhrenläuse) Pfirsich / Nektarine
#> 6 Blattläuse (Röhrenläuse) Pflaume
#> 7 Blattläuse (Röhrenläuse) Zwetschge
#> 8 Spinnmilben Olive
#> 9 Spinnmilben Apfel
#> 10 Spinnmilben Quitte
#> 11 Spinnmilben Aprikose
#> 12 Spinnmilben Kirsche
#> 13 Spinnmilben Pfirsich / Nektarine
#> 14 Spinnmilben Birne
#> 15 Spinnmilben Pflaume
#> 16 Spinnmilben Zwetschge
#> 17 Spinnmilben Walnuss
result3 <- resolve_cultures(example_dataset_2, current_register,
correct_culture_names = FALSE)
print(result3)
#> substance_de pNbr use_nr application_area_de culture_de
#> 1 Spirotetramat 7839 5 Obstbau Birne
#> 2 Spirotetramat 7839 7 Obstbau Kirschen
#> 3 Spirotetramat 7839 18 Obstbau Steinobst
#> 4 Spirotetramat 7839 18 Obstbau Steinobst
#> 5 Spirotetramat 7839 18 Obstbau Steinobst
#> 6 Spirotetramat 7839 18 Obstbau Steinobst
#> 7 Spirotetramat 7839 18 Obstbau Steinobst
#> 8 Spirotetramat 7839 22 Obstbau Obstbau allg.
#> pest_de leaf_culture_de
#> 1 Birnblattsauger Birne
#> 2 Kirschenfliege <NA>
#> 3 Blattläuse (Röhrenläuse) Aprikose
#> 4 Blattläuse (Röhrenläuse) Kirsche
#> 5 Blattläuse (Röhrenläuse) Pfirsich / Nektarine
#> 6 Blattläuse (Röhrenläuse) Pflaume
#> 7 Blattläuse (Röhrenläuse) Zwetschge
#> 8 Spinnmilben Obstbau allg.
result4 <- resolve_cultures(example_dataset_3, current_register,
correct_culture_names = TRUE)
print(result4)
#> substance_de pNbr use_nr application_area_de culture_de
#> 1 Pirimicarb 2210 3 Feldbau Getreide
#> 2 Pirimicarb 2210 3 Feldbau Getreide
#> 3 Pirimicarb 2210 3 Feldbau Getreide
#> 4 Pirimicarb 2210 3 Feldbau Getreide
#> 5 Pirimicarb 2210 3 Feldbau Getreide
#> 6 Pirimicarb 2210 3 Feldbau Getreide
#> 7 Pirimicarb 2210 3 Feldbau Getreide
#> 8 Pirimicarb 2210 3 Feldbau Getreide
#> 9 Pirimicarb 2210 3 Feldbau Getreide
#> 10 Pirimicarb 2210 3 Feldbau Getreide
#> pest_de leaf_culture_de
#> 1 Blattläuse (Röhrenläuse) Korn (Dinkel)
#> 2 Blattläuse (Röhrenläuse) Emmer
#> 3 Blattläuse (Röhrenläuse) Hartweizen
#> 4 Blattläuse (Röhrenläuse) Wintergerste
#> 5 Blattläuse (Röhrenläuse) Sommergerste
#> 6 Blattläuse (Röhrenläuse) Wintertriticale
#> 7 Blattläuse (Röhrenläuse) Winterroggen
#> 8 Blattläuse (Röhrenläuse) Sommerhafer
#> 9 Blattläuse (Röhrenläuse) Sommerweizen
#> 10 Blattläuse (Röhrenläuse) Winterweizen
# }