I have lots of categorical variables that have the same response options (likert scale). I want to collapse the number of response options for all of them. How can I do this in bulk instead of one at a time?
I found a thread from 2020 on this page that included the code below (I inserted my data though) but I am not able to get it to work. Any guidance would be appreciated.
A,B,C,D,E are my variable names
Response options are on a 5 or 7 point likert scale and I would like to collapse to a 3 point scale.
data1mod <- data1(
A = c("Strongly support","Support","Don't know/No opinion","Oppose","Strongly oppose"),
B = c("Strongly support","Support","Somewhat support", "Don't know/No opinion","Somewhat oppose","Oppose","Strongly oppose"),
C = c("Strongly support","Support","Somewhat support", "Don't know/No opinion","Somewhat oppose","Oppose","Strongly oppose"),
D = c("Strongly support","Support","Somewhat support", "Don't know/No opinion","Somewhat oppose","Oppose","Strongly oppose"),
E = c("Strongly support","Support","Somewhat support", "Don't know/No opinion","Somewhat oppose","Oppose","Strongly oppose"))
data1mod %>% mutate_all(list(rec = ~ recode(.,
"Strongly support","Support","Somewhat support"="Support",
"Don't know/No opinion"="Don't know/No opinion"
"Somewhat oppose","Oppose","Strongly oppose"="Oppose",
.default = NA_character_)))
This is the error I get: Error in data1(A = c("Strongly support", "Support", "Don't know/No opinion", :
could not find function "data1"