如何将列表中只包含值==3的列的元素子集?

问题描述 投票:0回答:1
>List
 [[1]]         col1    col2
  2013-07-17   0.150    1
  2013-08-14   0.150    1
  2013-09-18   0.150    1
 [[1]]         col1    col2
  2013-07-17   0.150    1
  2013-08-17   0.150    1
  2013-09-17   0.150    1
 [[1]]         col1    col2
  2013-07-17   0.150    3
  2013-08-17   0.150    3
  2013-09-17   0.150    1

如何只提取列表中只包含value==3列的元素。输出应该是这样的。

   >List
  [[1]]        col1   col2
  2013-07-17   0.150    3
  2013-08-17   0.150    3
r list
1个回答
1
投票

您可以使用 lapplysubset

output <- lapply(List, subset, col2 == 3)

如果你喜欢 tidyverse这可以通过以下方式实现

purrr::map(List, dplyr::filter, col2 == 3)
© www.soinside.com 2019 - 2024. All rights reserved.