簡體   English   中英

使用地圖從嵌套列表中提取

[英]Using map to pluck from nested list

我試圖用自己熟悉purrrmappluck ,我有一個深深的嵌套列表:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM