I have a dataframe with some columns where 99 should be considered as missing values (NA) and other columns where 999 was the value given for this purpose.
dat$variable1 <- ifelse(dat$variable1 == 99, NA, dat$EC)
dat$variable2 <- ifelse(dat$variable2 == 99, NA, dat$EC)
dat$variable3 <- ifelse(dat$variable3 == 99, NA, dat$EC)
dat$variable4 <- ifelse(dat$variable4 == 99, NA, dat$EC)
dat$variable5 <- ifelse(dat$variable5 == 999, NA, dat$EC)
dat$variable6 <- ifelse(dat$variable6 == 999, NA, dat$EC)
dat$variable7 <- ifelse(dat$variable7 == 999, NA, dat$EC)
I'd like to find a better way to do that, because sometimes we can have many many columns to deal with. I don't know how to loop over the specific variables that I should replace these values for NA and I'm not aware of a package that could help me with that (I'm a beginner in R).
Aucun commentaire:
Enregistrer un commentaire