Reputation: 91
I have a list of dataframes, and many have only 1 row which is causing issues for ggplot. How exactly can I automate removing these dataframes?
Upvotes: 1
Views: 133
Reputation: 887891
We can use Filter
from base R
Filter(function(x) nrow(x) > 1, lst)
Or with sapply
lst[sapply(lst, nrow) > 1]
Or with keep
from purrr
library(purrr)
keep(lst, ~ nrow(.x) > 1)
lst <- list(data.frame(col1 = 1, col2 = 2), data.frame(col1 = 1:5, col2 = 6:10))
Upvotes: 4