[R] fast matrix-vector multiplication
Martin Maechler
maechler at stat.math.ethz.ch
Tue Dec 15 08:51:02 CET 2009
>>>>> "GC" == Gray Calhoun <gray.calhoun at 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 <bbom419 at 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.
More information about the R-help
mailing list