vendredi 22 juillet 2016

Ifelse on text to create a new column in R

data:

weather
sunny
sunny rainy
cloudy
rainy
cloudy sunny

I want to add a new column that contains a 1 if it was sunny during the day and a 0 if it was not sunny. It works for the first row of data but not on the others.

df$sunny <- ifelse(df$weather %in% "sunny", "1", "0")  

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire