I am trying to create a variable using ifelse, and would like the column to be 0 when the condition is not true, but they are showing up as NA. Any tips?
df$z <- ifelse (df$x == 1 |
df$y == 1, 1,
ifelse (df$x == 2 |
df$y == 2 ,2, 0))
My understanding is that the above code should make everything that isn't 1 or 2 coded as 0, but I only get 1, 2 and NA. No zeros.
Aucun commentaire:
Enregistrer un commentaire