R: how do you merge/combine two environments?

前端 未结 3 1332
[愿得一人]
[愿得一人] 2021-02-18 23:01

This is a simple question but the answer is apparently not so simple... Is it possible to combine environments in R?

E1 = new.env()
E2 = new.env()
E1$x = 25
E2$y         


        
3条回答
  •  感动是毒
    2021-02-18 23:54

    You can do it by combining them, converting the environments to lists, and then converting back:

    E3 <- as.environment(sapply(c(E1,E2),as.list))
    ls(env=E3)
    [1] "x" "y"
    E3$x
    [1] 25
    E3$y
    [1] 7
    

提交回复
热议问题