Replace values in R, "Yes" to 1 and "No" to 0

Viewed 58474

I am working with weatherAUS dataset that is avaiable in the R libraries. I am trying to replace "Yes" to 1 and "No" to 0 in the RainTomorrow column.

I wrote this but it doesn't seem to work:

weather4$RainTomorrow[weather4$RainTomorrow=="Yes"]<-1 

I just says:

Warning message: In [<-.factor(*tmp*, weather4$RainTomorrow == "Yes", value = c(NA, : invalid factor level, NA generated

What does it mean and what should I do? I reckon I should use as.numeric or as.factor somewhere but I don't know how really.

3 Answers
Related