View source: R/ReformatLoops.R
loop_to_column_conversion | R Documentation |
Converting from loop to a format that is easy to analyze.
loop_to_column_conversion(data, name_column, variable_to_convert, type)
data |
The data containing the loops you need to convert |
name_column |
The column containing the variable which will eventually column header (see example) |
variable_to_convert |
What is the variable you would like to link to the name column |
type |
What is the type of variable you are expecting? "chr" for character, "num" for numeric, "int" for interger, and "fct" for factor. |
Rpackage file: ReformatLoops.R
name_column <- "crop_name"
variable_to_convert <- "crop_variable"
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")
))
number_of_loops <- find_number_of_loops(data, name_column)
loop_to_column_conversion(data, name_column, variable_to_convert, type = "chr")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.