I would like to create a new variable called season from my dataset(BirdCount_2008_2018) "Month" variable. The months appeared in integer: 1-12. I want to arrange 3-5 as spring, 7-11 as autumn, 12-2 as winter and the others as summer. I tried inputting
BirdCount_2008_2018$Season<-with(BirdCount_2008_2018,ifelse((Month==3|Month==4|Month==5),"Spring"),ifelse((Month==7|Month==8|Month==9|Month==10|Month==11),"Autumn"), ifelse((Month==12|Month==1|Month==2),"Winter","Summer"))
But there is an error, I kept trying similar codes, but I still can't figure out what is happening
Can someone help me? I am very new to R and really need help!!!!
EDIT: I have tried inputting codes as of the suggested answers to the other similar post, but I am still unable to create the new variable, please help, I am very lost, thanks a lot.
EDIT: Here is a code that I input
BirdCount_2008_2018 %>% mutate(Season = ifelse((Month == 7 | Month == 8 | Month == 9 | Month == 10 | Month == 11), "Autumn", ifelse((Month == 12 | Month == 1 | Month == 2), "Winter", ifelse((Month == 3 | Month == 4 | Month == 5), "Spring","Summer"))))
And the result:
# A tibble: 3,991 x 8
Species Sciname Year Month Day Count Location Season
Swan Goose Anser cygnoides 2008 1 NA 1 <NA> Winter
# ... with 3,981 more rows
But when I view the table, the last column of Season did not show up. First column of table view