I am trying to create a new variable "season" from month variable by using the following script:
alldata_n %>%
mutate(
season = case_when(
month %in% 10:12 ~ "Fall",
month %in% 1:3 ~ "Winter",
month %in% 4:6 ~ "Spring",
month %in% 7:9 ~ "Summer" ))
This is working but when i use the function to see the variable, the "season" variable doesn't show up.
alldata$
I tried to save the data in csv format but even then the save data doesn't show any "season" variable. Where am i going wrong? Can someone please help me with this?
Thanks in advance
CodePudding user response:
There are 2 issues with this piece of code.
- The variable
alldata_n
is mutated, but never stored. - Observe that the name
alldata
is not equal toalldata_n
So it should look like:
alldata <- alldata_n %>%
mutate(
season = case_when(
month %in% 10:12 ~ "Fall",
month %in% 1:3 ~ "Winter",
month %in% 4:6 ~ "Spring",
month %in% 7:9 ~ "Summer" ))
Calling alldata$season
now works.