如何删除列中满足数据条件的行 [英] How to remove rows where columns satisfy certain condition in data frame

查看:57
本文介绍了如何删除列中满足数据条件的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的数据帧

I have a data frame that looks like this

df <- data.frame(cbind(1:10, sample(c(1:5), 10, replace=TRUE)))
# in real case the columns could be more than two
# and the column name could be anything.

我要删除的所有行中所有列的值
小于5。
怎么做?

What I want to do is to remove all rows where the value of all its columns is smaller than 5. What's the way to do it?

推荐答案

df[!apply(df,1,function(x)all(x<5)),]

这篇关于如何删除列中满足数据条件的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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