[R] omit empty cells in crosstab?
hadley wickham
h.wickham at gmail.com
Sat Apr 25 02:11:19 CEST 2009
On Fri, Apr 24, 2009 at 3:12 PM, sjaffe <sjaffe at riskspan.com> wrote:
>
> small example:
>
> a<-c(1.1, 2.1, 9.1)
> b<-cut(a,0:10)
> c<-data.frame(b,b)
> d<-table(c)
> dim(d)
> ##result: c(10, 10)
>
> But only 9 of the 100 cells are non-zero.
> If there were 10 columns, the table have 10 dimensions each of length 10, so
> have 10^10 elements, too much even to fit in memory
Here's one way with the plyr package:
library(plyr)
ddply(c, names(c), nrow)
Find more about plyr at http://had.co.nz/plyr
Hadley
--
http://had.co.nz/
More information about the R-help
mailing list