create_long_data_frame {eufmdis.adapt} | R Documentation |
Reshape wide data frame with combined column names
Description
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.
Usage
create_long_data_frame(dat, categories, name_categories, starts_with = FALSE)
Arguments
dat |
Data frame with combined column names (e.g. |
categories |
Character vector of possible values of categories in the
column names (e.g. |
name_categories |
Character; name of the newly created column that contains the categories in the long data frame |
starts_with |
Logical; Flag indicating how the combined columns should
be identified. |
Details
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.
Value
A long data frame where the combined columns have been split up
Author(s)
Ian Kopacka