I'm trying to replace a range of values, 1 to 14, with a new range of values, 0 to 13 using the ifelse function in R. My code is getting lengthy:
new_var <- with(data, ifelse(var==1, 0, ifelse(var==2, 1, ifelse(var==3, 2, ... ifelse(var==14, 13, NA))))
Is there a way to specify ranges using ifelse? I tried this, but it didn't work:
new_var <- with(data, ifelse(var==c(1:14), c(0:13), NA))
Aucun commentaire:
Enregistrer un commentaire