Thomas L Jones wrote:
>
> My question is a seemingly simple one. I have a bunch of user-
> defined functions which compute such-and-such objects. I want to be 
> able to define a variable in a particular function, then make use of 
> it later, perhaps in a different function, without necessarily 
> having to move it around in argument lists. In the C community, it 
> would be called a "global" variable.
> 
Global variables in R are used with <<- instead of <-.

For example:

x <- 1
y <- 1

f <- function() {
   x <- 2
   y <<- 2
}

f()

will turn y to 2 but will not change x.

Alberto Monteiro

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to