def_recode_all: Recode all columns in a dataset using a definitions list

Description Usage Arguments Value Examples

View source: R/run-recode-all.R

Description

Column names in values_tbl should match names in def_list

Usage

1
def_recode_all(values_tbl, def_list, .default = NULL, .missing = NULL)

Arguments

values_tbl

A data frame with values stored in a coded format.

def_list

A list of definition sets, likely produced by def_prep().

.default

If supplied, all values not otherwise matched will be given this value. If not supplied and if the replacements are the same type as the original values in .x, unmatched values are not changed. If not supplied and if the replacements are not compatible, unmatched values are replaced with NA.

.default must be either length 1 or the same length as .x.

.missing

If supplied, any missing values in .x will be replaced by this value. Must be either length 1 or the same length as .x.

Value

A data frame with the same rows and columns as values_tbl, with columns recoded according to def_recode

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
def_list <- tibble::tibble(variable   = c("A", "A", "B", "B", "C"),
                           value      = c(1,   2,   1,   2,   1),
                           definition = c("cat", "dog", "fred", "george", "lonely")) %>%
  def_prep(variable, value, definition, drop_solos = FALSE)

source_data <- tibble::tibble(ID = c("A1", "A2", "A3"),
                              A  = c(1, 1, 2),
                              B  = c(2, 1, 2),
                              C  = c(1, 1, 1))

def_recode_all(source_data, def_list)

davisadamw/definer documentation built on March 11, 2020, 4:14 a.m.