On Thu, 2007-02-08 at 16:53 +0100, Martin Maechler wrote:
> >>>>> "Albr" == Albrecht, Dr Stefan (AZ Private Equity Partner) <[EMAIL
> >>>>> PROTECTED]>
> >>>>> 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
______________________________________________
[email protected] 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.