[R] How to do it without for loops?

ronggui ronggui.huang at gmail.com
Tue Feb 28 14:18:07 CET 2006


This is the code:

x<-matrix(rnorm(20),5)
y<-list()
for (i in seq(nrow(x))) y[[i]]<-t(x[i,,drop=F])%*%x[i,,drop=F]
y[[1]]+y[[2]]+y[[3]]+y[[4]]+y[[5]]

How can I do it without using for loops?
Thank you in advance!
--
ronggui
Deparment of Sociology
Fudan University




More information about the R-help mailing list