On 9/02/2010, at 12:51 PM, Daniel Malter wrote:

> The for loop tries to write into an object that does not yet exist. Do
> month.observed=NULL prior to the loop.

Bad advice.  As Duncan Murdoch just pointed out, this is inefficient.
Compare:

> x <- NULL
> system.time(for(i in 1:50000) x[i] <- 42)
 user  system elapsed 
5.986   9.014  15.001

with

> x <- numeric(50000)
> system.time(for(i in 1:50000) x[i] <- 42)
 user  system elapsed 
0.151   0.002   0.153 

The former is forty times slower.  And things get rapidly worse as the length
of the loop increases.

        cheers,

                Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

______________________________________________
R-help@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.

Reply via email to