[R] case study of efficient R coding

Huntsinger, Reid reid_huntsinger at merck.com
Tue Oct 15 20:59:14 CEST 2002


t(X)%*%X or better crossprod(X) is the sum of outer products
of the rows of X. The (i,j) entry is the sum of X[k,i]*X[k,j]
over k, i.e., the (i,j) entry of the outer product of X[k, ]
with itself.

Reid Huntsinger

-----Original Message-----
From: Jason Liao [mailto:jg_liao at yahoo.com]
Sent: Tuesday, October 15, 2002 12:38 PM
To: r-help at stat.math.ethz.ch
Subject: [R] case study of efficient R coding


[...]
But first, does anyone know a vectorized way of coding (summing the
outter product of rows)

p = 10;
x = rnorm(p*p);
dim(x) = c(p.p);

var = array(0, c(p,p));
for(i in 1:p) var = var + x[i,]%*% t(x[i,]);

=====
Jason G. Liao, Ph.D.
Division of Biometrics
University of Medicine and Dentistry of New Jersey
335 George Street, Suite 2200
New Brunswick, NJ 08903-2688
phone (732) 235-8611, fax (732) 235-9777
http://www.geocities.com/jg_liao

__________________________________________________

Faith Hill - Exclusive Performances, Videos & More

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._

------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that may be confidential, proprietary copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named on this message.  If you are not the intended recipient, and have received this message in error, please immediately return this by e-mail and then delete it.

==============================================================================

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list