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)
___ | M | F
Cat | 9 | 4
Dog | 0 | 0
Rat | 4 | 3
I just would like to see those rows:
___ | M | F
Cat | 9 | 4
Rat | 4 | 3
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$animal <- droplevels(ds$animal)
with(ds, table(animal,gender))
here I used with because it prints headers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With