Skip to content
Prev 308102 / 398503 Next

uniq -c

On 16/10/2012 12:29 PM, Sam Steingold wrote:
The problem is that xtabs() and by() and related functions are designed 
for the case where all combinations of all factors exist. If you have a 
dataset where only a few exist, you could use sparseby() from the 
reshape package.

Syntax would be

sparseby(data=x, INDICES=x, FUN=nrow)

if you wanted a dataframe giving counts.

I just tried it, and on your two examples it gives a warning about 
coercing a list to a logical vector; I guess all(list(TRUE, TRUE)) was 
allowed when I wrote it, but isn't any more.  I'll send a patch to the 
maintainer.

Duncan Murdoch