Lets say we have something like this
df <- data.frame(species = c("Passer", "Turdus", "Turdus", "Gallus", "Anas", "Anas"),
season = c("breeding", "breeding", "non-breeding", "non-breeding", "breeding", "non-breeding"),
value = seq(1, 12, 2),
drop = c("no", "no", "dog", "dog", "cat", "cat"))
species season value drop
1 Passer breeding 1 no
2 Turdus breeding 3 no
3 Turdus non-breeding 5 dog
4 Gallus non-breeding 7 dog
5 Anas breeding 9 cat
6 Anas non-breeding 11 cat
I would like to select the rows that have species with both values of breeding season, i.e. breeding and non-breeding.
The outcome should look like this
species season value drop
2 Turdus breeding 3 no
3 Turdus non-breeding 5 dog
5 Anas breeding 9 cat
6 Anas non-breeding 11 cat
I gave it a couple tries with filter() but I couldn’t make it work. I suspect making a loop could be the way to go? Thanks!