you need to reset levels from the animal factor.
table(droplevels(ds$animal),ds$gender)
you can also just delete them from ds and then make a table
ds$anima <- droplevels(ds$animal) with(ds, table(animal,gender))
I used here because it prints the headers.
source share