I am trying to create a new vector "seasons" based off of the months vector already provided in my data. I am using the built-in txhousing dataset; I have already filtered the dataframe to only include information on the city of Houston and have called this new dataframe houston.
I have managed to recategorize the twelve months into four seasons, however, the way I did it is not efficient. Does anyone have any suggestions for how I can optimize this code? Whenever I tried to provide a range of months (e.g. houston[houston$month==(3:5),] %<>% mutate(seasons = "spring") I would get the error "In month == 3:5 : longer object length is not a multiple of shorter object length".
Thank you for any help! -an R newbie
houston[houston$month==(1),] %<>% mutate(seasons = "winter")
houston[houston$month==(2),] %<>% mutate(seasons = "winter")
houston[houston$month==(3),] %<>% mutate(seasons = "spring")
houston[houston$month==(4),] %<>% mutate(seasons = "spring")
houston[houston$month==(5),] %<>% mutate(seasons = "spring")
houston[houston$month==(6),] %<>% mutate(seasons = "summer")
houston[houston$month==(7),] %<>% mutate(seasons = "summer")
houston[houston$month==(8),] %<>% mutate(seasons = "summer")
houston[houston$month==(9),] %<>% mutate(seasons = "summer")
houston[houston$month==(10),] %<>% mutate(seasons = "fall")
houston[houston$month==(11),] %<>% mutate(seasons = "fall")
houston[houston$month==(12),] %<>% mutate(seasons = "winter")