当名称存储在变量中时,我试图按名称提取列表元素。即:
myList <- list(a = 1, b = 2, c = 3) ## list definition
## I can extract the second element like this:
myList$b
## but say I have a variable:
to_extract <- "b"
##can I do something like this?
myList$to_extract
谢谢!
以下所有工作。
myList[[to_extract]]
`[[`(myList, to_extract)
library(purrr)
pluck(myList, to_extract)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句