View source: R/create_long_data_frame.R
create_long_data_frame | R Documentation |
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)
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. |
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.
A long data frame where the combined columns have been split up
Ian Kopacka
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.