[R] Speed up code with for() loop

hck hans-christian.krumholz at uni-ulm.de
Thu Apr 28 19:27:35 CEST 2011


Hallo everybody,

I'm wondering whether it might be possible to speed up the following code:

Error<-rnorm(10000000, mean=0, sd=0.05)

estimate<-(log(1.1)-Error)

DCF_korrigiert<-(1/(exp(1/(exp(0.5*(-estimate)^2/(0.05^2))*sqrt(2*pi/(0.05^2))*(1-pnorm(0,((-estimate)/(0.05^2)),sqrt(1/(0.05^2))))))-1))
D<-100000
Delta_ln<-rep(0,D)
for(i in 1:D)
Delta_ln[i]<-(log(mean(sample(DCF_korrigiert,1000000,replace=TRUE))/(1/0.10)))

The calculation of the for-loop takes several hours even on a very quick
machine (4GHz, 8 GB RAM Windows 2008 Server 64bit). Has anybody an idea, how
to improve the for-line?

Thanks for helping me.
Hans

--
View this message in context: http://r.789695.n4.nabble.com/Speed-up-code-with-for-loop-tp3481680p3481680.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list