[R] How define global Variable?

Kristel Joossens kristel.joossens at econ.kuleuven.be
Mon Nov 28 15:34:47 CET 2005


The problem is that the a is within the function
You can easily solve this by

test <- function () { a <- "new"; return(a) }
a=test()

Best regards,
Kristel


(or test <- function () { return(a <- "new")})

svenknueppel at reilich.net wrote:
> Hello,
> 
> I try to define a global variable.
> 
> My example:
> 
> R> a <- "old"
> R> test <- function () { a <- "new" }
> R> test()
> R> a # shoud be "new"
> 
> This doesn't work. I would like to modify the variable "a" in a
> procedure. How can I do that.
> 
> Thank you for helping.
> 
> Sven Knüppel (Germany-Berlin)
> 
> 
> 
> ------------------------------------------------------------------------
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

-- 
__________________________________________
Kristel Joossens        Ph.D. Student
Research Center ORSTAT  K.U. Leuven
Naamsestraat 69         Tel: +32 16 326929
3000 Leuven, Belgium    Fax: +32 16 326732
E-mail:  Kristel.Joossens at econ.kuleuven.be
http://www.econ.kuleuven.be/public/ndbae49

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm




More information about the R-help mailing list