[R] How to increase the for() loop speed?

Erik Iverson iverson at biostat.wisc.edu
Thu Jun 12 18:46:09 CEST 2008


We would certainly need more information about your function to offer 
any specific advice, therefore I'll fall back on the general.  First 
there is no command that will increase a for loop speed, it is not as if 
they are artificially slowed down.

In general, you may be able to do whatever it is you are doing using 
vectorized calculations instead of looping, and/or by using a 
combination of the *apply functions.

You should read the latest issue of R News, as it has an article related 
to your question, and will explain my paragraphs above.  Find it here,

http://cran.r-project.org/doc/Rnews/

Finally, there is a special mailing list for using R for quantitative 
finance, perhaps you could a more detailed question there, search for 
R-SIG-Finance.

Erik

Rafael Barros de Rezende wrote:
> My routine is on Financial Econometrics (Yield Curve Modeling). It is 
> very intensive. And I have heard that the for() loop speed could be 
> increased with a command. I want to know if there a way to do it.
> 
> Best regards.
> 
> Rafael Barros de Rezende 
> 
> 
> 
> *---------- Original Message -----------*
> From: Erik Iverson <iverson at biostat.wisc.edu>
> To: Rafael Barros de Rezende <rafabarros at cedeplar.ufmg.br>
> Cc: r-help at r-project.org
> Sent: Thu, 12 Jun 2008 11:06:09 -0500
> Subject: Re: [R] How to increase the for() loop speed?
> 
>  > 13 minutes is a long time for a loop to simply send an email, what other
>  > calculations are going on?
>  >
>  > Rafael Barros de Rezende wrote:
>  > >    Dear R users,
>  > >
>  > >    I would like to know if there is a way to increase the for() 
> loop speed
>  > >    because in my routine the calculations are too slow.
>  > >
>  > >    Best regards.
>  > >    Rafael Barros de Rezende
>  > >    Cedeplar  - Center for Development and Regional Planning
>  > >    Face, UFMG ([1]http://www.cedeplar.ufmg.br 
> <http://www.cedeplar.ufmg.br/>)
>  > >    --
>  > >    Esta mensagem foi verificada pelo sistema de antivírus e
>  > >    acredita-se estar livre de perigo.
>  > >
>  > > References
>  > >
>  > >    1. http://www.cedeplar.ufmg.br/
>  > > ______________________________________________
>  > > R-help at r-project.org mailing list
>  > > https://stat.ethz.ch/mailman/listinfo/r-help
>  > > PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html 
> <http://www.r-project.org/posting-guide.html>
>  > > and provide commented, minimal, self-contained, reproducible code.
>  > >
>  >
>  > --
>  > Esta mensagem foi verificada pelo sistema de antivírus e
>  > acredita-se estar livre de perigo.
> *------- End of Original Message -------*
> 
> 
> -- 
> Esta mensagem foi verificada pelo sistema de antivírus e
> acredita-se estar livre de perigo.



More information about the R-help mailing list