lundi 20 avril 2020

Using ifelse and mutate to categorise a new column by previous column name

I am having issues where I need to categorise US states assigning two groups of five states as either rich or poor and every other state as middle. I am able to simply categorise as either rich or not using this code: twoe.data.frame <- mutate(us_contagious_diseases, wealth = ifelse(state == "Maryland"|state == "New Jersey"|state == "hawaii"|state == "Massachusetts"|state == "Connecticut", "rich","middle"))

Whilst I am struggling to figure out how to assign the other five states (not included in above code) to be considered poor.

I am very New to R and am unsure how to do this across the three conditions being rich, middle and poor. I can only seem to do two at a time.

What needs to be added to my code to classify the states of Louisiana, New Mexico, Arkansas, Mississippi, West Virginia as poor.

Aucun commentaire:

Enregistrer un commentaire