[R] Speed up sum of outer products?

From: AjayT <ajaytalati_at_googlemail.com>
Date: Tue, 01 Mar 2011 08:53:50 -0800 (PST)

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.

R-help_at_r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 01 Mar 2011 - 17:07:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 01 Mar 2011 - 18:20:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive