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 "local variable", ie a variable local to testf().
They are not the same.

As far as I remember, to assign a global variable from inside a
function you have to use the <-- operator.

(By the way, for 2dim arrays, there is also matrix().)

hih
Vincent

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to