[R] how to add names to an object created using assign

Fuchs Ira irafuchs at gmail.com
Sat Feb 21 00:32:58 CET 2009


If I assign a variable in a function, as in:

test=function(){
assign("a",c(1,2,3),env=.GlobalEnv)
}

How can I do the equivalent of:

names(a)=c("one","two","three")

within the function?

Merely adding the call to names does not work within the function as  
it only affects a local variable:

test=function(){
assign("a",c(1,2,3),env=.GlobalEnv)
names(a)=c("one","two","three")
}




More information about the R-help mailing list