在两个不同的数据框中删除公共行 [英] Dropping common rows in two different dataframes
本文介绍了在两个不同的数据框中删除公共行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是使用R的初学者。我有两个不同的数据框,例如称为df-1和df-2的图像。我想合并两个数据框并删除公共行。 (或者,我想删除常见的行并希望保留行的唯一ID。
I am a beginner using R. I have two different dataframes like the image called df-1 and df-2. I want to combine two dataframes and drop common rows. (Or I want to removal common rows and want to remain unique ID of rows.
因此,我要制作的内容类似于df-3。
A 合并
是不合适的,因为我不需要公共行。
Therefore, What I want to make is like df-3.
A merge
is not appropriate because I don't need common rows.
df-1
ID NUMBER FORM DATE CD AD
1 A15 200302033666 1 20031219 3 7
2 B67 200302034466 1 20031204 3 1
3 C15 200302034455 1 20031223 3 1
4 D67 200303918556 1 20030319 3 1
5 E48 200303918575 1 20030304 3 1
6 F80 200303918588 1 20030325 3 1
7 G63 200303918595 1 20030317 3 1
df-2
ID NUMBER FORM DATE CD AD
1 A15 200302033666 1 20031219 3 7
2 K99 200402034466 1 20041204 2 3
3 Z75 200502034455 2 20021222 1 6
4 D67 200303918556 1 20030319 3 1
5 E48 200303918575 1 20030304 3 1
6 F80 200303918588 1 20030325 3 1
7 G63 200303918595 1 20030317 3 1
df-3
ID NUMBER FORM DATE CD AD
1 B67 200302034466 1 20031204 3 1
2 C15 200302034455 1 20031223 3 1
3 K99 200402034466 1 20041204 2 3
4 Z75 200502034455 2 20021222 1 6
推荐答案
使用 rbind
合并 df1
和 df2
,然后选择独特的
值
Use rbind
to merge df1
and df2
and then selecet unique
values
df3 <-unique( rbind(df1,df2))
这篇关于在两个不同的数据框中删除公共行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文