View source: R/recode_valinvec.R
recode_valinvec | R Documentation |
Recode a specified variable in a data frame or tibble based on a provided recode map. If the recode map is empty, the original variable is retained under a new name.
recode_valinvec(data, var, recode_map, new_var)
data |
A data frame or tibble. |
var |
A variable to be recoded. |
recode_map |
A named vector specifying the recode map. |
new_var |
Name of the new variable holding the recoded values. |
A data frame or tibble with the new variable added.
# Example data
print(sailor_students)
# Define a recode map for gender
recode_map_gender <- c("Female" = "F", "Male" = "M", "Other" = "X")
# Recode gender
sailor_students_recoded <-
recode_valinvec(sailor_students, gender, recode_map_gender, recode_gender)
# A tibble with a recoded gender variable
print(sailor_students_recoded)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.