Lets suppose I have such a list including 3 dataframes named 1, 3 and 4:
1 3 4
1 A c(2, 1, 3, 1, 2) c(1, 1, 2) c(1, 1)
2 B c(1, 1, 1, 3, 2) c(2, 1, 2) c(2, 1)
The dataframes have all the same columns (A and B) but different counts of rows as you see. How do I erase the rows which have values < 2 in column B for all dataframes in the list?
I tried lapply with any:
list <- lapply(list, function(x) {x <- any(x[,c(2)] < 2);x})
Judicious use of
lapply()and simple subsetting is as good as any approach. Using your data inl:This does what you want
giving: