leaf_recode: Recode columns of a data frame

Description Usage Arguments Value See Also Examples

View source: R/leaf_recode.R

Description

Recodes values in a data frame by joining with a data frame of recoded values.

Usage

1
leaf_recode(tbl, code_tbl)

Arguments

tbl

Data frame to modify

code_tbl

A data frame of recoding values, either:

  • A data frame with three columns, variable, code, and value. variable matches the column name to recode in tbl. code matches the encoded values in tbl. value contains the values that each code should be replaced with. (For example, see leafpeepr::acs_codes_long.)

  • A data frame with two adjacent columns for each column to be recoded in tbl. One column contains encoded values and can have any name. The other contains recoded values and has the same name as the column to recode in tbl. (For example, see leafpeepr::acs_codes.)

Each code column can contain either literal codes or one-sided formulas. (For example, compare leafpeepr::acs_race_codes and leafpeepr::acs_age_codes.)

Value

A data frame with selected columns recoded

See Also

dplyr::case_when() to recode data using formulas

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# A data frame of encoded data
acs_nh

# A data frame of recode values
acs_sex_codes

#Recode
leaf_recode(acs_nh, acs_sex_codes)

# You can also specify recoding using formulas
acs_bpl_codes
leaf_recode(acs_nh, acs_bpl_codes)

# Or a mix of values and formulas
acs_educ_codes
leaf_recode(acs_nh, acs_educ_codes)

# You can use also use a data frame with recode values for multiple columns
# Either a wide data frame
acs_codes
leaf_recode(acs_nh, acs_codes)

# Or a long data frame
acs_codes_long
leaf_recode(acs_nh, acs_codes_long)

rossellhayes/leafpeepr documentation built on Feb. 29, 2020, 12:48 a.m.