从数据帧中删除行,其中行匹配字符串 [英] Remove Rows From Data Frame where a Row match a String

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

问题描述

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



例如:

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

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

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

解决方案

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

  dtfm [!dtfm $ C ==Foo,] 

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

  dtfm [dtfm $ C!=Foo,] 

或者,使用 subset()

  subset( dtfm,C!=Foo)


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

For example:

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

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

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

解决方案

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", ]

Or, even shorter using subset():

subset(dtfm, C!="Foo")

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

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