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

jim holtman jholtman at gmail.com
Thu Jun 12 20:20:48 CEST 2008


The first thing to do is to run Rprof and determine where time is
being spent.  It may be that it is one of the functions that you are
calling inside the loop that is taking the majority of time and if
that is the case, there may not be any improvement other than coming
up with a different algorithm.  'for' loops themselves are not
necessarily that slow; it is usually the case that you may not be
preallocating storage, or there are some other things happening.
Rprof will help determine where the problem might be.

On Thu, Jun 12, 2008 at 11:52 AM, Rafael Barros de Rezende
<rafabarros at cedeplar.ufmg.br> 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)
>   --
>   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
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list