Creating similar variable from old information

This was very helpful, thank you


To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

More specifically for you, it would be sufficient to run your workflow up until the point where you would have run the code you pasted here, i.e. when you have gss1000 but havent adjusted it yet, and provide a 20record sample. Therefore the code you would use to provide this to the forum would be


Then, format your forum posts by using triple backticks like so :

my code looks nice


Is this what you mean?

c(NA, 1, NA, NA, 1, 1, NA, 3, 3, 6, NA, 5, NA, 4, 2, 1, 1, NA,
3, 4)

I would have preferred the code as I wrote it without the $vote part, but its acceptable...

It's a massive data set with 5000 values

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.

  vote=c(NA, 1, NA, NA, 1, 1, NA, 3, 3, 6, NA, 5, NA, 4, 2, 1, 1, NA,
  3, 4),
# 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"
(gss1000 <- mutate(gss1000,
                   new_vote = factor(case_when(vote==1~2,
                                          TRUE ~ 1),
                                       labels = c('unkown',

# unkown   never minimal average 
# 7       5       6       2