The following line of code seems fairly straight forward, yet it is kicking
back an error message:
for (i in
1:length(mean.natveg.frac)){month.observed[i]=as.numeric(names(mean.natveg.frac[i]))%%12}
Error message:
Error in month.observed[i] = as numeric(names(mean.natveg.frac[i]))%%12 :
object 'month.observed' not found
Seems like its not found because I'm trying to define it. Also
length(mean.natveg.frac) = 103
Eric
--
View this message in context:
http://n4.nabble.com/object-xxx-not-found-tp1473729p1473729.html
Sent from the R help mailing list archive at Nabble.com.
emorway wrote:> The following line of code seems fairly straight forward, yet it is kicking > back an error message: > for (i in > 1:length(mean.natveg.frac)){month.observed[i]=as.numeric(names(mean.natveg.frac[i]))%%12} > > Error message: > > Error in month.observed[i] = as numeric(names(mean.natveg.frac[i]))%%12 : > object 'month.observed' not found > > Seems like its not found because I'm trying to define it. Also > length(mean.natveg.frac) = 103You can't index the object before it is defined. You can assign to non-existent elements of an object, but it is very inefficient. So the best fix is to put the line month.observed <- numeric(length(mean.natveg.frac)) before the for loop. Duncan Murdoch
The for loop tries to write into an object that does not yet exist. Do
month.observed=NULL prior to the loop.
HTH,
Daniel
-------------------------
cuncta stricte discussurus
-------------------------
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On
Behalf Of emorway
Sent: Monday, February 08, 2010 6:38 PM
To: r-help at r-project.org
Subject: [R] object 'xxx' not found
The following line of code seems fairly straight forward, yet it is kicking
back an error message:
for (i in
1:length(mean.natveg.frac)){month.observed[i]=as.numeric(names(mean.natveg.f
rac[i]))%%12}
Error message:
Error in month.observed[i] = as numeric(names(mean.natveg.frac[i]))%%12 :
object 'month.observed' not found
Seems like its not found because I'm trying to define it. Also
length(mean.natveg.frac) = 103
Eric
--
View this message in context:
http://n4.nabble.com/object-xxx-not-found-tp1473729p1473729.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
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.