I have a dataframe from which I'd like to extract a subset based on a group condition: for a given year x, if a species only counts 1 individual, then remove it from the df.
I am able to have a subset of this kind:
df %>%
group_by(species,year) %>%
summarise(n_inds = n()) %>%
filter(n_inds > 1)
which gives this results
# A tibble: 1,915 x 3
espece year n_inds
<fct> <dbl> <int>
1 Agelaioides badius 2003 5
2 Agelaioides badius 2004 3
3 Agelaioides badius 2005 4
4 Amaurospiza moesta 2005 2
5 Amaurospiza moesta 2014 2
6 Amblyramphus holosericeus 2006 2
7 Ammodramus humeralis 2010 4
8 Ammodramus humeralis 2011 3
9 Anabacerthia amaurotis 2001 3
10 Anabacerthia amaurotis 2004 5
# ... with 1,905 more rows
but it's not totally what I want. This df tells me, for example for the 1st row, that they are 5 individuals of Agelaioides badius in 2003 that I want to keep in my original df, alongside all the columns with the different measurements for each corresponding bird (I'm working on birds).
If someone has a solution! :)
Thanks a lot
PS: the original df is counting 19501 observations of 9 variables.