The function identifies columns whose name contains a combination of two categorical characteristics (e.g. farm type and output parameter), splits them up and reshapes the data to a long format.
create_long_data_frame(dat, categories, name_categories, starts_with = FALSE)A long data frame where the combined columns have been split up
Data frame with combined column names (e.g. type_A_farms,
type_B_farms, type_A_animals, type_B_animals)
Character vector of possible values of categories in the
column names (e.g. c("type_A", "type_B"))
Character; name of the newly created column that contains the categories in the long data frame
Logical; Flag indicating how the combined columns should
be identified. starts_with = TRUE enforces a stricter search mode
where only columns are considered whose name starts with the given string.
Ian Kopacka
The function looks for combined columns based on the category names provided
in the argument categories. Two modes of searching are possible:
starts_with = FALSE (=default) looks for all columns whose name
contains the strings in categories, whereas starts_with = TRUE
only includes columns whose name starts with the string. Relevant
combinations of #' values that are not found in the wide data frame are
filled with NA in the ling data frame.