vendredi 30 juin 2017

ifelse trying to create conditional column from Month column

I have a large data set and I am currently trying to create a column based on the month for either Winter (Sept - Mar) or Summer (Apr - Aug). Most things I have encountered to help split, want to split into 4 seasons, where for my data I need it specifically into these two seasons based on month. I have a Day column that is in

"%m/%d/%Y"

so I created a column with just the month

TAD_rawdata$Month <- format(as.Date(TAD_rawdata$Day), "%m")

which gave me a character string with the month as either "01" - "12"

so I tried using an ifelse statement to create my season column:

TAD_rawdata$Season <- ifelse (TAD_rawdata$Month == c("04", "05", "06", "07", "08"), "SUMMER", "WINTER" )

but it gives me this error

Warning message: In TAD_rawdata$Month == c("04", "05", "06", "07", "08") : longer object length is not a multiple of shorter object length

and then it just seems to randomly assign winter or summer, like the month will be for example 4 (so should be summer) but it will give it both summer and winter....

please help :) thanks

Aucun commentaire:

Enregistrer un commentaire