如何通过r中的变量名来对环境进行子集化

Ali*_*sro 3 environment r subset

我想通过变量名称对环境进行子集化.

e <- new.env(parent=emptyenv())
e$a <- 1
e$b <- 2
e$d <- 3
e[ls(e) %in% c("a","b", "c")]
### if e was a list, this would return the subset list(a=1, b=2)
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚如何按名称对环境元素进行子集化.使用lapply或eapply也不起作用.通过变量名称对环境进行子集的正确或简单方法是什么?谢谢.

the*_*ail 5

好的,经过多思考后,我可以建议:

mget(c("a","b"), envir=e)
#$a
#[1] 1
#
#$b
#[1] 2
Run Code Online (Sandbox Code Playgroud)