I have a data frame like so
> df
a b c d
1 1 2 A 1001
2 2 4 B 1002
3 3 6 B 1002
4 4 8 C 1003
5 5 10 D 1004
6 6 12 D 1004
7 7 13 E 1005
8 8 14 E
It works if you use duplicated
twice:
df[!(duplicated(df[c("c","d")]) | duplicated(df[c("c","d")], fromLast = TRUE)), ]
a b c d
1 1 2 A 1001
4 4 8 C 1003
7 7 13 E 1005
8 8 14 E 1006
Make a new object with the 2 columns:
df_dups <- df[c("c", "d")]
Now apply it to your main df:
df[!duplicated(df_dups),]
Looks neater and easy to see/change columns that you are using.