如果满足一行条件,请删除多行 [英] Remove multiple rows if condition for one row is met

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

问题描述

我有以下数据集:

ID   value
abc    1
abc    NA
abc    2
def    5
def    1 
def    4

我知道如何识别包含NA的行的ID.我想做的是删除包含ID的所有行(如果一行包含NA).在这种情况下:abc的一行显示一个NA,因此应删除ID = abc的所有行,以便数据框如下所示:

I know how to identify the ID of the row that contains a NA . What I want to do is to delete all rows with the ID if one row contains a NA. In this case: One row of abc shows an NA, thus all rows with ID = abc should be removed, so that the dataframe looks like this:

ID   value
def    5
def    1 
def    4

在此先感谢您的帮助.

欢呼

推荐答案

您可以使用 ID 的否定的 %in%!拥有 NA 来删除具有ID的所有行,如果一行包含NA .

You can use the negated ! %in% of ID which have an NA to delete all rows with the ID if one row contains a NA.

x[!x$ID %in% unique(x$ID[is.na(x$value)]),]
#   ID value
#4 def     5
#5 def     1
#6 def     4

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

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