dimanche 6 décembre 2015

nested ifelse statement - multiple values for 1 output

Sorry for this question, but I can't seem to find an answer for it on the web. I have a dataset with a variable with values from 1 to 5. I want to create a new column where values 1 and 3 become A, 2 and 4 become B and 5 becomes C

data$new <- ifelse(data$value == c("1", "3"), "A", ifelse(data$value == c("2", "4"), "B", "C"))

This works for 1, 2 and 5. But for some reason it doesn't accept me putting multiple numbers for A and B. How can I tell R to create A if it is 1 or 3?

Thanks in advance,

Aucun commentaire:

Enregistrer un commentaire