【问题标题】:using pipe and dplyr to append item to list使用管道和 dplyr 将项目附加到列表
【发布时间】:2020-07-30 21:08:04
【问题描述】:

我有一个数据框 mappedAttModel 和一个名为 features 的列表。我想附加管道项目。我收到错误对象 (.)not found。

for (i in 1:length(features)){
 mappedAttModel %>%
 dplyr::filter(.data$att == features[[i]]) %>%
 dplyr::select(.data$model) %>%
 purrr::pluck(1,1) %>%
 #append to the list
 ###l1 <- append(l1,.)
 }```

【问题讨论】:

    标签: r dplyr pipe magrittr


    【解决方案1】:

    您可以使用purrr::map 返回一个列表,而不是使用 for 循环增加一个列表。像这样的东西应该可以工作

    l1 = 
      purrr::map(1:length(features),
                 function(i) {
                   mappedAttModel %>%
                     dplyr::filter(.data$att == features[[i]]) %>%
                     dplyr::select(.data$model) %>%
                     purrr::pluck(1,1)
                 }
      )
    

    请注意,地图有多种变体,具体取决于您想要的输出类型。

    【讨论】:

      猜你喜欢
      • 2011-05-15
      • 2016-01-23
      • 2015-04-16
      • 2020-07-30
      • 2011-10-12
      • 2013-12-24
      • 1970-01-01
      • 1970-01-01
      • 2021-08-01
      相关资源
      最近更新 更多