[R] object 'xxx' not found
Rolf Turner
r.turner at auckland.ac.nz
Tue Feb 9 01:03:54 CET 2010
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}}
More information about the R-help
mailing list