[R] R vs Matlab {Re: R in Industry}

Manuel Morales Manuel.A.Morales at williams.edu
Thu Feb 8 17:51:57 CET 2007


On Thu, 2007-02-08 at 16:53 +0100, Martin Maechler wrote:
> >>>>> "Albr" == Albrecht, Dr Stefan (AZ Private Equity Partner) <stefan.albrecht at apep.com>
> >>>>>     on Thu, 8 Feb 2007 16:38:18 +0100 writes:
<snip> 
>     Albr> And, I was very astonished to realise, Matlab is very, very much faster
>     Albr> with simple "for" loops, which would speed up simulations considerably.
> Can you give some evidence for this statement, please?
> 
> At the moment, I'd bet that you use forgot to pre-allocate a
> result array in R and do something like the "notorious horrible" (:-)
> 1-dimensional
> 
>   r <- NULL
>   for(i in 1:10000) {
> 	r[i] <- verycomplicatedsimulation(i)
>   }
> 
> instead of the "correct"
> 
>   r <- numeric(10000)
>   for(i in 1:10000) {
> 	r[i] <- verycomplicatedsimulation(i)
>   }

Would a similar speed issue arise for the construction:
r <- vector()
...

-- 
Manuel A. Morales
http://mutualism.williams.edu


More information about the R-help mailing list