Skip to content
Prev 79030 / 398502 Next

extracting from data frame multiple times

On Fri, 14 Oct 2005, Ido M. Tamir wrote:

            
The first step is to find out what is too slow, using Rprof().  It may be 
the t.test or it may be the by().

If it is the by() you could put the numeric data into two matrices
   x1<-df[,2:4]
   x2<-df[,5:7]
order them so that the same "item" entries were adjacent, compute the 
start and end indices for each group, and do something like
lapply(1:howevermany, function(i) t.test(x1[start[i]:end[i],],x2[start[i]:end[i]))
Even just turning df into a matrix might help

If it is the repeated t.test() calls that are too slow you need to speed 
them up.  You can probably rowsum() to compute means and variances for all 
the t-tests at once.

 	-thomas