Re: [R] problem accumulating array within a function over loops

From: <>
Date: Wed 05 Oct 2005 - 20:10:26 EST

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().)

Vincent mailing list PLEASE do read the posting guide! Received on Wed Oct 05 20:23:39 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:20:00 EST