recode_formula: Recode a data frame with formulas.

Description Usage Arguments Value Examples

Description

The data frame is recoded according to a correspondance table containing formulas.
The correpondance table contains a least three fields : condition, column and value.

Usage

1
recode_formula(data, data_recode, new_vars = TRUE)

Arguments

data

A data frame.

data_recode

The correspondance table containing formulas.

new_vars

If TRUE then it computes all variables referenced in data_recode, not only variables in data at the first place.

Value

A recoded data frame.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Recode without condition
patchr::recode_formula(
data = dplyr::tibble(test = 1L),
data_recode = dplyr::tibble(condition = NA_character_, column = "test", value = "2L")
)

# Recode with condition
patchr::recode_formula(
data = dplyr::tibble(test = c(1L, 2L)),
data_recode = dplyr::tibble(condition = "test == 2", column = "test", value = "3L")
)

stephLH/source.maj documentation built on May 13, 2020, 1:54 p.m.