s-news
[Top] [All Lists]

Re: Matrix multiplication

To: Riyanto Wibowo <riyantowibowo@yahoo.com.sg>, s-news@lists.biostat.wustl.edu
Subject: Re: Matrix multiplication
From: "Richard M. Heiberger" <rmh@temple.edu>
Date: Thu, 23 Jun 2005 00:31:32 -0400
## The most efficient way to multiply two matrixes in S is to
## use the matrix multiplication function directly.

a <- matrix(runif(100000), 50000, 2)
b <- c(10, 20)
date()
P <- a %*% b
date()

## This takes less than 1 second


## Do it 1000 times:
date()
for (i in 1:1000)
   P <- a %*% b
date()
## This loop takes 26 seconds, or .026 seconds for each multiplication.

Rich

<Prev in Thread] Current Thread [Next in Thread>