I have a categorical variable with 88 levels (counties) and I want to aggregate those into five larger geographical regions. Is there a more elegant way to do this than a huge amount of ifelse statements (like below)?
survey.responses$admin<-ifelse(survey.responses$CNTY=="Lake","Northeast",
ifelse(survey.responses$CNTY=="Traverse","Northwest",
ifelse(survey.responses$CNTY=="Ramsey","Central",
ifelse(survey.responses$CNTY=="Cottonwood","South","out of state")
except imagine that CNTY has 88 levels! Any thoughts?
Aucun commentaire:
Enregistrer un commentaire