name and place each element of a list in Global Environment

前端 未结 2 1555
余生分开走
余生分开走 2020-12-19 20:56

If you have a list but you want each element of the list to be it\'s own separate element in the global environment e.g.

alist <- list( c(1,2         


        
相关标签:
2条回答
  • 2020-12-19 21:18

    Use list2env

    alist <- list( a=c(1,2), b=c(3,4) )  # naming list elements
    list2env(alist, envir = .GlobalEnv)
    
    0 讨论(0)
  • 2020-12-19 21:27

    If your elements aren't named, then you can do mapply with assign:

    mapply(assign, list("a","b"), alist, MoreArgs=list(envir=.GlobalEnv))
    > ls()
    ## [1] "a"     "alist" "b"
    

    But what Roland said.

    0 讨论(0)
提交回复
热议问题