extract_new_values: Extract New Units

View source: R/ExtractNewValues.R

extract_new_valuesR Documentation

Extract New Units

Description

A function for extracting any new values from a survey

Usage

extract_new_values(
  data,
  loop_or_individual_column = "loop",
  column_name = NA,
  column_pattern = NA,
  number_of_loops = NA
)

Arguments

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.

Details

Rpackage file: ExtractNewValues.R

Value

A list of the individual values for that value (excluding NA values)

Examples


# 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

l-gorman/rhomis-R-package documentation built on Nov. 8, 2023, 6:46 a.m.