View source: R/ExtractNewValues.R
extract_new_values | R Documentation |
A function for extracting any new values from a survey
extract_new_values(
data,
loop_or_individual_column = "loop",
column_name = NA,
column_pattern = NA,
number_of_loops = NA
)
data |
The whole data-set from which the units are to be extracted from |
loop_or_individual_column |
Options are: "loop", "column". Specifying whether you want to extract new values from a loop or a column. |
column_name |
If loop_or_individual_column=="column", then here we specify which column to search for |
column_pattern |
The pattern which is used to identify the columns. For example if trying to extract new crop names, these come in the form "crop_name_1", "crop_name_2", "crop_name_3". The pattern here would be "crop_name" |
number_of_loops |
If loop_or_individual_column=="loop", then here we specify how many loops to search for. |
Rpackage file: ExtractNewValues.R
A list of the individual values for that value (excluding NA values)
# Example code for a crop loop
column_pattern <- "crop_name"
number_of_loops <- 2
data <- tibble::tibble(
crop_name_1 = c("maize", "cassava", "millet"),
random_columns = c("maize", "cassava", "millet"),
crop_name_2 = c("potato", NA, "cucumber")
)
result <- extract_new_values(data,
loop_or_individual_column = "loop",
column_pattern = "crop_name",
number_of_loops = 2
)
# expected_result is: c("maize","cassava","millet","potato","cucumber")
# Example code for an individual column
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.