Yes, the cause is memory use patterns, but the price is steep nonetheless.

E.g.:

rate<-log(400*1.1^(1:30)) # runs about 27x times as fast as the following
(test via 'microbenchmark') 

rate<-numeric(30)
for (i in 1:30){
   rate[i]<-log(400*1.1^i)
}

When manipulating large arrays, the difference can easily be a few seconds
vs. an hour or more. And if many such arrays need to be run, the difference
is between "difficult" and "not feasible". 

-Dan



--
View this message in context: 
http://r.789695.n4.nabble.com/For-Loops-please-help-tp4711882p4711887.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to