[R] omit empty cells in crosstab?

sjaffe sjaffe at riskspan.com
Fri Apr 24 22:12:58 CEST 2009


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 wrote:
> 
> sjaffe <sjaffe <at> 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() would exceed the memory space (on a
>> 32bit
>> machine). Is there any way to produce a table with empty cells omitted?
>> (without first producing the whole table and then removing rows.)
> 
> It would be easier if you had a reproducible base example, but I 
> suggest to create ONE new factor of the pasted levels using unique(), 
> and  creating a table of these.
> 
> Dieter
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: http://www.nabble.com/omit-empty-cells-in-crosstab--tp23222263p23224071.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list