I need to remove the rows from the table function output, which have 0 counts in all the columns. Is there any easy way to do that?
table(ds$animal,ds$gender
you need to drop levels from the factor animal.
table(droplevels(ds$animal),ds$gender)
you can also just drop them from ds and then do the table
ds$anima <- droplevels(ds$animal) with(ds, table(animal,gender))
here I used with because it prints headers.