Nitro Nitro - 5 months ago 25
R Question

R keep rows with at least one column greater than value

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?

Answer Source

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:

filter_all(df, any_vars(. > 10))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download