[R] efficiency with "%*%"

Uwe Ligges ligges at statistik.uni-dortmund.de
Thu Jan 26 14:34:25 CET 2006


dimitrijoe at ipea.gov.br wrote:

> Hi,
> 
> x and y are (numeric) vectors. I wonder if one of the following is more
> efficient than the other:
> 
> x%*%y
> 
> or
> 
> sum(x*y)
> ?

I'd try

   x <- rnorm(1000000)
   y <- rnorm(1000000)
   system.time(x%*%y)
   system.time(sum(x*y))

and finally (hint, hint!):

   system.time(crossprod(x, y))

Uwe Ligges


> Thanks,
> Dimitri Szerman
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list