R keep rows with at least one column greater than value

前端 未结 3 817
再見小時候
再見小時候 2020-11-28 15:32

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?

3条回答
  •  清歌不尽
    2020-11-28 16:23

    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))
    

提交回复
热议问题