如何使用高阶函数(例如 lapply 或 map)而不是 for-loop 来根据特定索引过滤数据帧列表?

How to use higher-order function (e.g. lapply or map) instead of for-loop to filter through a list of data frames based on certain index?

正如主题所暗示的,我如何用 lapply/map/etc 编写以下操作才能在 R 中更有效率?

for(i in 1:length(tbl)){
  tbl[[i]] <- filter(tbl[[i]], tbl[[i]][, 7] >= 10)
}

这个想法基本上是从列表的每个元素(数据框)中过滤第 7 列,以便输出仅提供所有数据框的第 7 列中包含 10 或更大的值。我试过这样的东西,但没有让代码工作:

lapply(tbl, function(x) filter(x, tbl[[x]][, 7] >= 10))
lapply(tbl, function(x) x[x[,7] >= 10,])

或使用dplyr::filter

lapply(tbl, function(x) filter(x, x[,7] >= 10))

使用purrr::map

map(tbl, ~filter(.x, .x[,7] >= 10))