[R] For Loops please help!!

Dan D
Sat, 05 Sep 2015 16:31:40 -0000

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.