[R] fast matrix-vector multiplication

2009-12-14 Thread parkbomee






Hi all,

Is there a way to do a matrix multiplication in a faster way?
I am making a product of a matrix (composed of a lot of dummy variables) and a 
vector, and is there any way to make it faster?
The simple X %*% y takes too long a time.
I know using sparse matrix would help, but don't know how to do it i R.


Thank you.


  
_
[[elided Hotmail spam]]

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] fast matrix-vector multiplication

2009-12-14 Thread Gray Calhoun
Check out crossprod and the Matrix package (capitalized); there's also
a discussion of their speed gains in the R newsletter that should turn
up with a search and in the vignette as well.

-Gray

On Monday, December 14, 2009, parkbomee bbom...@hotmail.com wrote:






 Hi all,

 Is there a way to do a matrix multiplication in a faster way?
 I am making a product of a matrix (composed of a lot of dummy variables) and 
 a vector, and is there any way to make it faster?
 The simple X %*% y takes too long a time.
 I know using sparse matrix would help, but don't know how to do it i R.


 Thank you.



 _
 [[elided Hotmail spam]]

         [[alternative HTML version deleted]]

 __
 r-h...@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


-- 
Gray Calhoun

Assistant Professor of Economics
Iowa State University

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] fast matrix-vector multiplication

2009-12-14 Thread Martin Maechler
 GC == Gray Calhoun gray.calh...@gmail.com
 on Mon, 14 Dec 2009 19:26:44 -0600 writes:

GC Check out crossprod and the Matrix package (capitalized); there's also
GC a discussion of their speed gains in the R newsletter that should turn
GC up with a search and in the vignette as well.

Yes, use the 'Matrix' package.

For the problem you mention,   X  being a design matrix of
regression problem,
you may be interested in the   sparse.model.matrix()  function
which constructs such a sparse X from a formula and a data
frame.
With 

  library(Matrix)
  example(sparse.model.matrix)

you get a few (small sample) examples.

Martin Maechler, ETH Zurich

GC -Gray

GC On Monday, December 14, 2009, parkbomee bbom...@hotmail.com wrote:
 
 
 Hi all,
 
 Is there a way to do a matrix multiplication in a faster way?
 I am making a product of a matrix (composed of a lot of dummy variables) 
and a vector, and is there any way to make it faster?
 The simple X %*% y takes too long a time.
 I know using sparse matrix would help, but don't know how to do it i R.
 
 
 Thank you.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.