# NOT RUN {
# recode 1-4 to 0-3
dummy <- sample(1:4, 10, replace = TRUE)
recode_to(dummy)
# recode 3-6 to 0-3
# note that numeric type is returned
dummy <- as.factor(3:6)
recode_to(dummy)
# lowest value starting with 1
dummy <- sample(11:15, 10, replace = TRUE)
recode_to(dummy, lowest = 1)
# lowest value starting with 1, highest with 3
# all others set to NA
dummy <- sample(11:15, 10, replace = TRUE)
recode_to(dummy, lowest = 1, highest = 3)
# recode multiple variables at once
data(efc)
recode_to(efc, c82cop1, c83cop2, c84cop3, append = FALSE)
library(dplyr)
efc %>%
select(c82cop1, c83cop2, c84cop3) %>%
mutate(
c82new = recode_to(c83cop2, lowest = 5),
c83new = recode_to(c84cop3, lowest = 3)
) %>%
head()
# }
Run the code above in your browser using DataLab