I have a dataset with 11 variables describing ‘reasons for using e-cigarettes’ (ecig2crav, ecig2quit, ecig2symp, smokefree, exterior, bothering, rednoquit, red2quit, toxic5, cheaper5, cantstop), all are factor variables with 4 levels:
1=Not at all true,
2=Not very true,
3=Somewhat true,
4=Very true.
I want a function to create a new (labelled) factor variable which collapses these four categories into two: Not true (levels 1 and 2) and True (levels 3 and 4). How can I do this in a quick way in R? I want to create a new factor variable for each of the original variables. At the moment I have the code for the first two variables as
data %>%
mutate(ecig2crav_rec=recode(ecig2crav, "Not at all true"="Not true", "Not very true"="Not true", "Somewhat true"="True", "Very true"="True", .default = NA_character_),
ecig2quit_rec=recode(ecig2quit, "Not at all true"="Not true", "Not very true"="Not true", "Somewhat true"="True", "Very true"="True", .default = NA_character_))
I wonder if there is a way to avoid to write the recoding rules for each variable as they all share the same rules. Thanks.
Polly