View source: R/ExtractNewValues.R
merge_and_simplify_core_values | R Documentation |
When extracting new values from the RHoMIS dataset, some variables appear in multiple columns. For example with units, we can have "crop_yield_units" and "crop_yield_units_other". These are all crop_yield units and we would like to ensure they are aggregated appropriately.
merge_and_simplify_core_values(
list_of_unique_core_values,
main_item,
categories_to_merge
)
list_of_unique_core_values |
A nested list of new values from a RHoMIS survey |
main_item |
The primary item that you want to merge. In "crop_yield_units" and "crop_yield_units_other", the main item would be "crop_yield_units" |
categories_to_merge |
A named list of the categories which go together, please see example |
This is heavily linked to the "extract_new_core_units" function.
Rpackage file: ExtractNewValues.R
categories_to_merge <- list(
crop_name = c("crop_name"),
livestock_name = c("livestock_name"),
crop_yield_units = c("crop_yield_units_other"),
crop_sold_price_quantityunits = c("crop_price_quantityunits_other"),
unitland = c(
"areaunits_other",
"unitland_owned",
"unitland_rentin",
"unitland_rentout"
),
milk_units = c("milk_amount_units_other"),
milk_sold_price_timeunits = c("milk_amount_time_units_other"),
bees_honey_production_units = c("bees_honey_production_units_other"),
eggs_units = c("eggs_amount_units_other"),
eggs_sold_price_timeunits = c("eggs_sold_price_timeunits_other"),
fertiliser_units = c("fertiliser_units_other")
)
list_of_unique_core_values <- c(list(
crop_sold_price_quantityunits = c(
"cropPriceA",
"cropPriceB",
"cropPriceC"
),
crop_price_quantityunits_other = c(
"cropPriceD",
"cropPriceE",
"cropPriceF"
),
random_unimportant_column = c("bla", "bla", "bla")
))
main_item <- "crop_sold_price_quantityunits"
categories_to_merge <- list(
crop_name = c("crop_name"),
livestock_name = c("livestock_name"),
crop_yield_units = c("crop_yield_units_other"),
crop_sold_price_quantityunits = c("crop_price_quantityunits_other"),
unitland = c(
"areaunits_other",
"unitland_owned",
"unitland_rentin",
"unitland_rentout"
),
milk_units = c("milk_amount_units_other"),
milk_sold_price_timeunits = c("milk_amount_time_units_other"),
bees_honey_production_units = c("bees_honey_production_units_other"),
eggs_units = c("eggs_amount_units_other"),
eggs_sold_price_timeunits = c("eggs_sold_price_timeunits_other"),
fertiliser_units = c("fertiliser_units_other")
)
expected_result <- c(
"cropPriceA",
"cropPriceB",
"cropPriceC",
"cropPriceD",
"cropPriceE",
"cropPriceF"
)
merge_and_simplify_core_values(
list_of_unique_core_values,
main_item,
categories_to_merge
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.