R 保留至少一列大于值的行 [英] R keep rows with at least one column greater than value

查看:23
本文介绍了R 保留至少一列大于值的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个包含几百行和几百列的数据框.如何保留至少有一个大于 10 的值的行?

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?

推荐答案

您可以使用 rowSums 来构造基 R 中的条件:

You can use rowSums to construct the condition in base R:

df[rowSums(df > 10) >= 1, ]

<小时>

使用 dplyr (0.7.0),现在你可以像这样使用 filter_all:


with dplyr (0.7.0), now you can use filter_all like this:

library(dplyr)
filter_all(df, any_vars(. > 10))

这篇关于R 保留至少一列大于值的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆