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)
#> Error in library(readxl): there is no package called ‘readxl’
codes <- read_excel("countryCodes.xls", 1)
#> Error in read_excel("countryCodes.xls", 1): could not find function "read_excel"
replace_by_table(mydata$var1, codes, "iso2c", "full.country.names")
#> Error: object 'codes' not found