Thanks: [S] is there a cumouter() like function?

Fei Chen (fchen@stern.nyu.edu)
Mon, 24 Aug 1998 12:22:20 -0400 (EDT)


many thanks to Nick Ellis, Christian Keller, Lutz Prechelt, Patrick Burns,
Claude Nadeau and Bill Dunlap for answer my question: crossprod is the
solution!
--------------------------------------
original question: how to avoid the following loop?

> a_matrix(rnorm(30),10,3) # some random N x 3 matrix
> b_matrix(0,3,3)
> for(i in 2:10)
> b_b+a[i-1,]%o%a[i,]

answer (Dunlap):

The fastest is probably a call to crossprod (which is shorthand for
x %*% t(y)):

f2 <-
function(a = A)
{
if(nrow(a) < 2)
stop("a must have at least 2 rows")
i <- 2:nrow(a)
crossprod(a[i - 1, ], a[i, ])
}
-----------------------------------------
thanks so much!

fei

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news