So I have a data frame with occurences of specimens of fish belonging to several species (there are occurences of several specimens belonging to the same species). The data frame has a column with the name of the species of a certain specimen, as well as a grade from A to E that was previously assigned to every specimen belonging to that species (that's why both the specimens of the species Tilapia zilli have the grade C, the grade is assigned to a whole species and not to a specimen individually).
What I want is basically to count for each grade (from A to E), how many species have been assigned to it. Not how many specimens (which are the occurence in this data frame), but the species. And in particular, I would prefer to return the number of species for each grade at a time. For example, a line of code to get the number of species with grade A and another to get the number of species with grade B, and so on...
species | Grade |
-----------------------------------
Tilapia guineensis | B |
Tilapia zillii | C |
Fundulus rubrifrons | A |
Eutrigla gurnardus | D |
Sprattus sprattus | A |
Gadus morhua | E |
Tilapia zillii | C |
Gadus morhua | B |
I tried this but it didn't work:
length(unique(df$species[df$grade=="A",]))