An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130201/b82557fd/attachment.pl>
Loading a list into the environment
5 messages · Jonathan Greenberg, Gabor Grothendieck, Rui Barradas +1 more
On Fri, Feb 1, 2013 at 5:24 PM, Jonathan Greenberg <jgrn at illinois.edu> wrote:
R-helpers: Say I have a list: myvariables <- list(a=1:10,b=20) Is there a way to load the list components into the environment as variables based on the component names? i.e. by applying this theoretical function to myvariables I would have the variables a and b loaded into the environment without having to explicitly define them.
?list2env -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
Hello,
Something like this?
myfun <- function(x, envir = .GlobalEnv){
nm <- names(x)
for(i in seq_along(nm))
assign(nm[i], x[[i]], envir)
}
myvariables <- list(a=1:10,b=20)
myfun(myvariables)
a
b
Hope this helps,
Rui Barradas
Em 01-02-2013 22:24, Jonathan Greenberg escreveu:
R-helpers: Say I have a list: myvariables <- list(a=1:10,b=20) Is there a way to load the list components into the environment as variables based on the component names? i.e. by applying this theoretical function to myvariables I would have the variables a and b loaded into the environment without having to explicitly define them. --j
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130202/8806b5d9/attachment.pl>
2 days later
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130204/067bc58d/attachment.pl>