[R] drop zero slots from table?

Sam Steingold sds at gnu.org
Wed Sep 19 17:51:08 CEST 2012


I find myself doing
--8<---------------cut here---------------start------------->8---
tab <- table(...)
tab <- tab[tab > 0]
tab <- sort(tab,decreasing=TRUE)
--8<---------------cut here---------------end--------------->8---
all the time.
I am wondering if the "drop 0" (and maybe even sort?) can be effected by
some magic argument to table() which I fail to discover in the docs?
Obviously, I could use droplevels() to avoid 0 counts in the first
place, but I do not want to drop the levels in the data.
-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://ffii.org http://truepeace.org
http://www.memritv.org http://honestreporting.com http://dhimmi.com
MS Windows: error: the operation completed successfully.



More information about the R-help mailing list