[R] variable scope
VBMorozov@lbl.gov
VBMorozov at lbl.gov
Sat Aug 3 04:38:54 CEST 2002
Dear R-guRus:
I would like to pass variables to a function in R in "by reference",
e.g Fortran style.
For example, suppose I have the following code
x<-c(1:10)
y<-1
MyFunc<-function(x,y) {y<-sum(x); return(NULL)}
MyFunc(x,y)
print(y)
in this case print(y) will produce "1" instead of 55 (which is sum(x)) -
how do I make sure that afte the function is run, y remembers the
value that was given to it within a function ????
Of course I could always do something like
MyFunc<-fuction(x) {return(sum(x)}; y<-MyFunc(x)
but in the real life I have a much more complex problem so I really
would like to be able to pass variables to functions by reference.
Thank you very much,
Vladimir
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list