Home > Software engineering >  Combing cell values within variable?
Combing cell values within variable?

Time:10-27

im sure this question already exists on this site, but I'm having trouble finding it.

I want to collapse certain values within a variable. For example, I have a variable called Race. Within the Race variable, I want to combine the observations Refused and Unknown since there are only a few observations of each, and I think its fair to treat them the same for my analysis. Thanks!

CodePudding user response:

Something like this should work:

library(dplyr) 
df$Race[df$Race %in% c("Refused", "Unknown") ] <- “Refused/Unknown"
  •  Tags:  
  • r
  • Related