user4378398
user4378398

Reputation:

If Else Statement and Removing NA's

I am using an ifelse statement to tell the program to categorize months into their respective quarters. For example January-March (I), April-June (II).....etc. I use the following ifelse statement:

eight$quarter<-ifelse(eight$month=="01", eight$quarter=="I", 0)

Whenever there is an "01" value in the column titled, "month" for some reason the "quarter" column comes up with the value on NA. Everything else is fine, as values 02-12 come up zero. I am curious as to where my coding has gone wrong so I may remove the NA's and replace them with the respective quarter number.

Upvotes: 0

Views: 217

Answers (1)

Cath
Cath

Reputation: 24074

You can try :

eight$quarter<-ifelse(eight$month=="01", "I", 0)

Upvotes: 2

Related Questions