【发布时间】:2020-03-18 16:09:47
【问题描述】:
我正在尝试熟悉 purrr、map 和 pluck,并且我有一个嵌套很深的列表:
test_list <-
list(
outer_1 = list(
list(
inner_1 = list(pluck = "String I Want", dontpluck = "other string")
)
)
)
$outer_1
$outer_1[[1]]
$outer_1[[1]]$inner_1
$outer_1[[1]]$inner_1$pluck
[1] "String I want"
$outer_1[[1]]$inner_1$dontpluck
[1] "other string"
我想提取"String I want"
我知道我可以使用
test_list$outer_1[[1]]$inner_1$pluck
但我想用 map 来抽象这个,但我错过了一些步骤。 (主要是我不知道如何使用map 模拟[[1]] 部分 - 类似于:
map(test_list, "outer_1") %>%
map("inner_1") %>%
map("pluck")
期望的输出
[1] "String I want"
【问题讨论】:
-
您的列表深度为 4,但您只有三个级别,即
outer_1、inner_1和pluck