I’m currently working on some ecological research data and tried to do this for hours now. I have a data frame similar, but much larger to this one:
beetles <- data.frame(Area=c("A","A","A","B","B","B","C","C","D","D","D","D"),
Year =c(1993, 1994, 1994, 1994,1995, 1995, 1996,1997,1998,1997,1996,1996),species=c("Harpalus latus","Amara ovata","Harpalus latus","Dromius agilis","Amara ovata","Harpalus latus","Amara ovata","Harpalus latus","Harpalus latus","Amara ovata","Dromius agilis","Harpalus latus"), field_season= c(1,2,2,1,2,2,1,2,3,2,1,1))
What I want to do is this: I have beetle data for 4 research areas, sampled over a range of years. For the analysis, I need a column with the number of field season per research area (field_season) each species was caught. I'm looking for the column named "field_season" which is currently not in my data.frame. To give a bit more context: For the analysis I want to split my data set and see how much the beetle communities differed over the field seasons carried out.
I tried to use:
beetles %>% group_by(Area) %>% mutate(field_season = year ?)
but can't figure out how to do this. Please, if anyone can point me in the right direction, that would be very much appreciated.