ok, thanks, but this one doesnt have a vote field at all, not sure what happened for you....anyway,
Try using case when to assign the values.
(gss1000<-data.frame(
vote=c(NA, 1, NA, NA, 1, 1, NA, 3, 3, 6, NA, 5, NA, 4, 2, 1, 1, NA,
3, 4),
some_other_columns=1:20))
#
# if it is missing or NA, I wan to code as 1 and assign the label "unknown",
# if the value is 1, I want to assign value of 2 with label "never",
# if between 2-4, I want to assign value of 3 with label "minimal",
# and if between 5-7, I want to assign value of 4 with label "average"
library(tidyverse)
(gss1000 <- mutate(gss1000,
new_vote = factor(case_when(vote==1~2,
between(vote,2,4)~3,
between(vote,5,7)~4,
TRUE ~ 1),
labels = c('unkown',
'never',
'minimal',
'average'))))
table(gss1000$new_vote)
# unkown never minimal average
# 7 5 6 2