s-news
[Top] [All Lists]

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

To: s-news@wubios.wustl.edu
Subject: Thanks: [S] is there a cumouter() like function?
From: Fei Chen <fchen@stern.nyu.edu>
Date: Mon, 24 Aug 1998 12:22:20 -0400 (EDT)
In-reply-to: <Pine.GSO.3.96.980824082624.365u-100000@jaques>
Reply-to: Fei Chen <fchen@stern.nyu.edu>
Sender: owner-s-news@wubios.wustl.edu
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

<Prev in Thread] Current Thread [Next in Thread>
  • Thanks: [S] is there a cumouter() like function?, Fei Chen <=