jeudi 28 décembre 2017

Create new column variables based upon condition in R

I don't know why this is not working. I have tried it various ways and it just does not work. It's not that I get an error using the if-statements I made myself, but it doesn't apply right.

Basically, there is a column Data$Age and a column Data$Age2.

If Data$Age is value 50 - 100, I want Data$Age2 to say "50-100 Years" for that particular row.

Likewise, if Data$Age is 25-50, I want Data$Age2 to say 25-50 Years" for the rows to which it applies.

What would the cleanest way to go about doing this in R?

Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire