[R] apply on large arrays

Erich Neuwirth erich.neuwirth at univie.ac.at
Thu Feb 14 00:52:12 CET 2008


I have a big contingency table, approximately of size 60*2*500*500,
and I need to count the number of cells containing a count of 1 for each 
of the factors values defining the first dimension.
Here is my attempt:

tab1<-with(pisa1,table(CNT,GENDER,ISCOF,ISCOM))
tab2<-apply(tab1,1:4,function(x)ifelse(sum(x)==1,1,0))
tab3<-apply(tab2,1,sum)

Computing tab2 is very slow.
Is there a faster and/or more elegant way of doing this?
-- 
Erich Neuwirth, University of Vienna
Faculty of Computer Science
Computer Supported Didactics Working Group
Visit our SunSITE at http://sunsite.univie.ac.at
Phone: +43-1-4277-39464 Fax: +43-1-4277-39459



More information about the R-help mailing list