R: optimal way of computing the "product" of two vectors

Posted by Musa on Stack Overflow See other posts from Stack Overflow or by Musa
Published on 2010-06-14T13:21:33Z Indexed on 2010/06/14 14:02 UTC
Read the original article Hit count: 136

Filed under:

Hi,

Let's assume that I have a vector

r <- rnorm(4)

and a matrix W of dimension 20000*200 for example:

W <- matrix(rnorm(20000*200),20000,200)

I want to compute a new matrix M of dimension 5000*200 such that m11 <- r%*%W[1:4,1], m21 <- r%*%W[5:8,1], m12 <- r%*%W[1:4,2] etc. (i.e. grouping rows 4-by-4 and computing the product).

What's the optimal (speed,memory) way of doing this?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about r