require(purrr)
list <- list(
node = list(a = list(y = 1, t = 1), b = list(y = 1, t = 2)),
node = list(a = list(y = 1, t = 3), b = list(y = 1, t = 4)))
如何用 purrr 选择所有“t”值?
您可以使用modify_depth
为此,如果您知道要从哪个级别提取信息。
你想拉t
out 为嵌套列表,即第 2 级。
modify_depth(list, 2, "t")
$node
$node$a
[1] 1
$node$b
[1] 2
$node
$node$a
[1] 3
$node$b
[1] 4
The purrr modify
函数系列返回与输入相同类型的对象,因此您需要unlist
获取向量而不是列表。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)