-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
Of Sam Steingold
Sent: Wednesday, September 19, 2012 9:13 AM
To: r-help at r-project.org
Subject: Re: [R] drop zero slots from table?
Function
--8<---------------cut here---------------start------------->8---
sorted.table <- function (vec) {
tab <- table(vec)
tab <- tab[tab > 0]
sort(tab, decreasing=TRUE)
}
--8<---------------cut here---------------end--------------->8---
does what I want but it prints "vec" instead of the name of its
argument:
--8<---------------cut here---------------start------------->8---
vec
A B
10 3
--8<---------------cut here---------------end--------------->8---
how do I pass all arguments of sorted.table() on to table() as is?
thanks!
* Sam Steingold <fqf at tah.bet> [2012-09-19 11:51:08 -0400]:
I find myself doing
tab <- table(...)
tab <- tab[tab > 0]
tab <- sort(tab,decreasing=TRUE)
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.