Dear R helpers,
I am having trouble with an array inside a loop.
I wish to accumulate the results of a function in an array within
the function, over several loops of a program outside the function.
The problem is that the array seems to re-set at every entry to the
function. Here is an
Subject: [R] problem accumulating array within a function over loops
Dear R helpers,
I am having trouble with an array inside a loop.
I wish to accumulate the results of a function in an array within
the function, over several loops of a program outside the function.
The problem
Jonathan Williams a écrit :
maxrun=3; a=array(NA, c(3,5)); run=0
testf=function(x,y){
print(paste('Run:',run)) #check that the function knows about run
a[run,1:3]=runif(3); a[run,4]=x; a[run,5]=y #collect numbers into array a
}
a outside testf is a global variable.
a inside testf is a