s-news
[Top] [All Lists]

[S] Loop avoiding

To: s-news@wubios.wustl.edu
Subject: [S] Loop avoiding
From: Marcel Wolbers <wolbers@stat.math.ethz.ch>
Date: Wed, 29 Jul 1998 21:04:11 +0200
Sender: owner-s-news@wubios.wustl.edu
Dear S-users

I have a n*m matrix A and a m*n matrix B where n is large (say 10000).
The measure I'm interested in is
> max(diag(A%*%B))
However the calculation above takes too long, has to calculate many things
I don't need (the off-diagonal elements)  and uses too much memory for
n large.

Of course I could avoid the matrix multiplication by using a for-loop, i.e.
> x <- vector("numeric",10000)
> for (index in 1:10000) 
>  { x[index] <- A[index,]%*%B[,index] }
> max(x)

But there must be a more efficient way to do it...  
It should be easy but I just can't find it.

Thanks a lot for your help.

Marcel Wolbers
-----------------------------------------------------------------------
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>