从数据框中删除行与字符串匹配的行 [英] Remove Rows From Data Frame where a Row matches a String

查看:26
本文介绍了从数据框中删除行与字符串匹配的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否删除数据框中某行满足字符串匹配条件的所有行?

I do I remove all rows in a dataframe where a certain row meets a string match criteria?

例如:

A,B,C
4,3,Foo
2,3,Bar
7,5,Zap

我将如何返回一个排除所有 C = Foo 行的数据框:

How would I return a dataframe that excludes all rows where C = Foo:

A,B,C
2,3,Bar
7,5,Zap

推荐答案

只需使用带有否定符号 (!) 的 ==.如果 dtfm 是您的 data.frame 的名称:

Just use the == with the negation symbol (!). If dtfm is the name of your data.frame:

dtfm[!dtfm$C == "Foo", ]

或者,在比较中移动否定:

Or, to move the negation in the comparison:

dtfm[dtfm$C != "Foo", ]

或者,使用 subset() 甚至更短:

Or, even shorter using subset():

subset(dtfm, C!="Foo")

这篇关于从数据框中删除行与字符串匹配的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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