View source: R/ReformatLoops.R
map_to_wide_format | R Documentation |
A function to convert RHoMIS loops into a wider named format
map_to_wide_format(data, name_column, column_prefixes, types)
data |
The original dataframe containing the data to be reformatted |
name_column |
The name column (e.g. crop_name_1) |
column_prefixes |
The columns which need to be converted to the correct format |
types |
The data types for each of these columns "chr" for character, "num" for numeric, "int" for interger, and "fct" for factor. |
Rpackage file: ReformatLoops.R
a list of data frames for each of the variables
name_column <- "crop_name"
column_prefixes <- c("crop_variable", "crop_unit", "crop_price")
types <- c("chr", "chr", "chr")
data <- tibble::as_tibble(list(
crop_name_1 = c("banana", "cassava", NA, "millet"),
crop_name_2 = c("cassava", NA, "melon", "maize"),
random_crop_name_2 = c("blue", "green", "red", NA),
crop_name = c("orange", "purple", NA, "black"),
crop_variable_1 = c("ex1", "ex2", NA, NA),
crop_variable_2 = c("ex3", NA, "ex4", "ex5"),
crop_unit_1 = c("unit1", "unit2", "unit3", NA),
crop_unit_2 = c(NA, NA, "unit4", "unit5"),
crop_price_1 = c(NA, NA, NA, NA),
crop_price_2 = c(NA, NA, NA, NA)
))
map_to_wide_format(data, name_column, column_prefixes, types)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.