[R] Speed up sum of outer products?

AjayT ajaytalati at googlemail.com
Tue Mar 1 17:53:50 CET 2011


Hi, I'm new to R and stats, and I'm trying to speed up the following sum,

for (i in 1:n){
	C = C + (X[i,] %o% X[i,])   # the sum of outer products - this is very slow
according to Rprof()		
}

where X is a data matrix (nrows=1000 X ncols=50), and n=1000. The sum has to
be calculated over 10,000 times for different X. 

I think it is similar to estimating a co-variance matrix for demeaned data
X. I tried using cov, but got different answers, and it was'nt much quicker?

Any help gratefully appreciated, 

-- 
View this message in context: http://r.789695.n4.nabble.com/Speed-up-sum-of-outer-products-tp3330160p3330160.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list