Say I have a data frame with a few hundred rows and a few hundred columns. How would I keep rows that have at least one value greater than 10?
We can use lapply
with Reduce
df[Reduce(`|`, lapply(df, `>`, 10)), ]
set.seed(24)
df <- as.data.frame(matrix(sample(1:12, 5*20, replace=TRUE), ncol=5))
This is another option:
df[apply(df>10,1,any),]
You can use rowSums
to construct the condition in base R:
df[rowSums(df > 10) >= 1, ]
with dplyr
(0.7.0), now you can use filter_all
like this:
library(dplyr)
filter_all(df, any_vars(. > 10))