How to apply dplyr filter to list of data frames?
11,515
Using purrr
library(purrr)
map(list.DFs, ~filter(.x, Gold.fish.count == "Total"))
Obviously, you can do exactly the same with lapply:
lapply(list.DFs, function(x) filter(x, Gold.fish.count == "Total"))
Author by
Username
Updated on June 15, 2022Comments
-
Username almost 2 years
I have a
list()
of dataframes. I want to applydplyr
'sfilter()
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") )
But this gives an error:
Object 'Gold.fish.count' not found
.