为什么我用来存储循环数据的对象会抛出错误?
Why does the object I usee to store data from a loop throw an error?
nruns <- 100
NLCommand("set N-turtles 100")
for(i in 1:nruns) {
NLCommand("setup")
NLDoCommandWhile("count turtles > 99", "go", max.minutes=0)
timetaken[[i]]<-NLReport("ticks")}
timetaken
此代码在 timetaken 部分抛出错误:
Error in timetaken[[i]] <- NLReport("ticks") :
object 'timetaken' not found
为什么会这样?
评论中建议的行作为我问题的答案。
timetaken <- numeric(nruns)
nruns <- 100
NLCommand("set N-turtles 100")
for(i in 1:nruns) {
NLCommand("setup")
NLDoCommandWhile("count turtles > 99", "go", max.minutes=0)
timetaken[[i]]<-NLReport("ticks")}
timetaken
此代码在 timetaken 部分抛出错误:
Error in timetaken[[i]] <- NLReport("ticks") :
object 'timetaken' not found
为什么会这样?
评论中建议的行作为我问题的答案。
timetaken <- numeric(nruns)