Description Usage Arguments Value Examples
Recode variables based on a pre-defined mapping table.
1 |
x |
a data.frame |
table |
a data.frame with three columns: variable, category, new_category |
a recoded data.frame.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # the main data frame to be recoded
x <- data.frame(
id = 1:10,
gender = sample(c("m", "f", "fe"), 10, replace = TRUE),
labour = sample(c("employed, fulltime", "employed, part-time", "unemployed"), 10, replace = TRUE)
)
# create a mapping table
my_table <- data.frame(variable = c(rep("gender",3), rep("labour", 3)),
category = c("m", "f", "fe",
"employed, fulltime", "employed, part-time", "unemployed"),
new_category = c("male", "female", "female",
"employed", "employed", "unemployed"))
x_new <- recodeR::recode(x = x, table = my_table, verbose = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.