如何从data.frame中删除行,基于外部列表,使用R? [英] How to delete rows from a data.frame, based on an external list, using R?

查看:116
本文介绍了如何从data.frame中删除行,基于外部列表,使用R?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个简单的问题,但我仍然需要一些帮助来使用R。

This might be an easy question but i still need some help for using R.

我有一个data.frame(main_data),让我们说.. p>

I have a data.frame (main_data), lets say..

NAMES   AGE     LOC
Jyo     23      Hyd
Abid    27      Kar
Ras     24      Pun
Poo     25      Goa
Sus     28      Kar

我希望基于列表删除几行的名字。所以说我有另一个表的列表如下:

I wish to remove a few rows based on a list of names. So lets say I have another list of table as follows:

NAMES_list
Jyo
Ras
Poo

所以基于这个列表,如果任何一个名字与我上面的main_data表相匹配,那么我想删除整行它们,所以结果应该如下

So based on this list, if any of the names match to my above "main_data" table, then I would like to remove the whole row contianing them, so the result should be as follows

NAMES   AGE     LOC
Abid    27      Kar
Sus     28      Kar

任何人都可以帮助我如何使用R ?
感谢提前..:)

Can anyone help me how to achive this using R? Thanks in advance.. :)

推荐答案

在%% $ c>:

Use %in%:

main_data2 <- main_data[ ! main_data$NAMES %in% NAMES_list, ]

这篇关于如何从data.frame中删除行,基于外部列表,使用R?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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