replace_by_table: Replace by table

View source: R/replace_by_table.R

replace_by_tableR Documentation

Replace by table

Description

Use a codes table to recode variable. Might be useful for translation of labels, for example.

Usage

replace_by_table(
  variable = all.data$cntry,
  lookup.table = recodes2,
  matching.column = "cntry",
  replacement.column = "",
  save.levels.order = T
)

Arguments

variable

Variable to recode.

lookup.table

Data frame with (at least) two columns named in line with the following arguments: 'matching.column' and 'replacement.column'

matching.column

Character. Lookup table's column of containing (pattern) values simiar to ones in 'variable'

replacement.column

Character. Lookup table's column containing substitution values.

save.levels.order

Logical. If the level order should follow the matching.column's levels order.

Examples

library(readxl)
codes <- read_excel("countryCodes.xls", 1)
replace_by_table(mydata$var1, codes, "iso2c", "full.country.names")


MaksimRudnev/LittleHelpers documentation built on Nov. 5, 2024, 10:16 p.m.