删除另一个数据框中存在的行? [英] Delete rows that exist in another data frame?
本文介绍了删除另一个数据框中存在的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下两个数据框(示例):
I have the two following data frames (example):
df1:
name profile type strand
A 4.5 1 +
B 3.2 1 +
C 5.5 1 +
D 14.0 1 -
E 45.1 1 -
F 32.8 1 -
G 19.9 1 +
df2:
name
A
B
C
G
我想删除 df1
中 df1$name = df2$name
的行以获得以下内容:
I would like to delete the rows in df1
for which df1$name = df2$name
to get the following:
输出:
name profile type strand
D 14.0 1 -
E 45.1 1 -
F 32.8 1 -
如果有人能告诉我使用哪一段代码会很有帮助,起初看起来很简单,但我从昨天开始就搞砸了.
If anyone could tell me which piece of code to use it would be a lot of help, seemed simple at first but I've been messing it up since yesterday.
推荐答案
您需要 %in%
运算符.所以,
You need the %in%
operator. So,
df1[!(df1$name %in% df2$name),]
应该给你你想要的.
df1$name %in% df2$name
测试df1$name
中的值是否在df2$name
中!
运算符反转结果.
df1$name %in% df2$name
tests whether the values indf1$name
are indf2$name
- The
!
operator reverses the result.
这篇关于删除另一个数据框中存在的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文