查找数据框的补集(反连接) [英] Find complement of a data frame (anti - join)
本文介绍了查找数据框的补集(反连接)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个数据框(df 和 df1).df1 是 df 的子集.我想得到一个数据框,它是 df 中 df1 的补充,即返回第一个数据集的行,而第二个数据集不匹配.例如让,
I have two data frames(df and df1). df1 is subset of df. I want to get a data frame which is complement of df1 in df, i.e. return rows of the first data set which are not matched in the second. For example let,
数据框df:
heads
row1
row2
row3
row4
row5
数据框df1:
heads
row3
row5
那么期望的输出 df2 是:
Then the desired output df2 is:
heads
row1
row2
row4
推荐答案
Try anti_join
from dplyr
library(dplyr)
anti_join(df, df1, by='heads')
这篇关于查找数据框的补集(反连接)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文