如何将dplyr过滤器应用于数据帧列表? [英] How to apply dplyr filter to list of data frames?
本文介绍了如何将dplyr过滤器应用于数据帧列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个list()
数据帧.我想将dplyr
的filter()
应用于所有这些对象.
I have a list()
of dataframes. I want to apply dplyr
's filter()
to all of them.
到目前为止我尝试过的示例代码...
Example code of what I have tried so far...
require(dplyr)
list.DFs <- list(df1,df2)
lapply(
X = list.DFS,
FUN = filter(Gold.fish.count=="Total")
)
但这会导致错误:Object 'Gold.fish.count' not found
.
推荐答案
使用purrr
library(purrr)
map(list.DFs, ~filter(.x, Gold.fish.count == "Total"))
显然,您可以对lapply进行完全相同的操作:
Obviously, you can do exactly the same with lapply:
lapply(list.DFs, function(x) filter(x, Gold.fish.count == "Total"))
这篇关于如何将dplyr过滤器应用于数据帧列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文