FANDOM


Recoding variables Edit

# create 2 age categories  mydata$agecat <- ifelse(mydata$age > 70,  c("older"), c("younger")) 

# another example: create 3 age categories  attach(mydata) mydata$agecat[age > 75] <- "Elder" mydata$agecat[age > 45 & age <= 75] <- "Middle Aged" mydata$agecat[age <= 45] <- "Young" detach(mydata)