[英]Using map to pluck from nested list
我試圖用自己熟悉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"
一種方法可能是:
map_chr(pluck(test_list, "outer_1"), pluck, "inner_1", "pluck")
[1] "String I Want"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.