Re: [R] loops in R - about inefficiency

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri 24 Jun 2005 - 19:53:06 EST

On Fri, 24 Jun 2005, Vehbi Sinan Tunalioglu wrote:

> Can someone technically explain, why does it take so long with loops in R?

First please demonstrate that it does!

a <- 0
system.time(for(i in 1:1e6) a <- a+1)

takes 1 second for a million iterations and you think that is `so long'? If you do, the technical explanation is that R is interpreted rather than compiled.

More likely the problem is *how* you are using loops.

The FAQ mentions reference material on how to use R efficiently and it would be more productive to learn to do so rather than claim it is inefficient.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Fri Jun 24 19:55:22 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:02 EST