Re: [R] omit empty cells in crosstab?

2009-04-26 Thread Bernardo Rangel Tura
On Fri, 2009-04-24 at 13:12 -0700, sjaffe 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, s

Re: [R] omit empty cells in crosstab?

2009-04-24 Thread hadley wickham
On Fri, Apr 24, 2009 at 3:12 PM, sjaffe 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

Re: [R] omit empty cells in crosstab?

2009-04-24 Thread Phil Spector
I think the easiest way to deal with this problem is to paste together the values, use table on those, and then unpaste (strsplit) them back. Using the 10 columns with 10 levels example: set.seed(25) x = as.data.frame(replicate(10,sample(1:10,12,replace=TRUE))) res = apply(x,1,paste,collapse=':

Re: [R] omit empty cells in crosstab?

2009-04-24 Thread sjaffe
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 Dieter Menne w

Re: [R] omit empty cells in crosstab?

2009-04-24 Thread Peter Dalgaard
Dieter Menne wrote: sjaffe riskspan.com> writes: I have data with many factors, each taking many values. However, only relatively few combinations appear in the data, ie have nonzero counts, in other words the resulting table is sparse. Say we have 10 factors each with 10 levels. The result of

Re: [R] omit empty cells in crosstab?

2009-04-24 Thread Dieter Menne
sjaffe riskspan.com> writes: > > I have data with many factors, each taking many values. However, only > relatively few combinations appear in the data, ie have nonzero counts, in > other words the resulting table is sparse. Say we have 10 factors each with > 10 levels. The result of table() wou

Re: [R] omit empty cells in crosstab?

2009-04-24 Thread hadley wickham
Hi Steve, The general answer is yes, but the specific will depend on your problem. Could you provide a small reproducible example to illustrate your problem? Hadley On Fri, Apr 24, 2009 at 1:19 PM, sjaffe wrote: > > Perhaps this is a common question but I haven't been able to find the answer.