What is the most effective (ie efficient / appropriate) way to clean up a factor containing multiple levels that need to be collapsed? That is, how to combine two or more fa
Similar to @Aaron's approach, but slightly simpler would be:
x <- c("Y", "Y", "Yes", "N", "No", "H") x <- factor(x) # levels(x) # [1] "H" "N" "No" "Y" "Yes" # NB: the offending levels are 1, 2, & 4 levels(x)[c(1,2,4)] <- c(NA, "No", "Yes") x # [1] Yes Yes Yes No No # Levels: No Yes