Manassa Mauler Manassa Mauler - 15 days ago 8
R Question

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


This code throws an error at the timetaken section saying:

Error in timetaken[[i]] <- NLReport("ticks") :
object 'timetaken' not found


Why is this the case?

Answer

The line suggested in the comments works as an answer to my question.

timetaken <- numeric(nruns)
Comments