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@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.