I have this data example:
W1$age <- c(3,2,4,1,1,3,4,NA,2,NA)
I want to create a column where:
-
1 is replaced by 0
-
2,3,4 are replaced by 1
-
everything else is NA
I have this code:
library(memisc)
W1$age2 = cases(
"0"= W1$age == 1,
"1" = W1$age == 2 | W1$age == 3 | W1$age == 4,
"NA" = W1$age != c("0", "1", "2", "3", "4")
)
it gives me this error (I googled it but I didn't find it):
Error in if (any(done == 0) && any(done > 1)) msg("conditions are neither exhaustive nor mutually exclusive") else if (any(done == :
missing value where TRUE/FALSE needed
In addition: Warning message:
In W1$age != c("0", "1", "2", "3", "4") :
longer object length is not a multiple of shorter object length
I hope you can help me either to fix it with some alternatives, thanks a lot!
Aucun commentaire:
Enregistrer un commentaire