1

I have a file (called example.txt) that looks like the following:

A B C  
D E F  
H I C  
Z B Y  
A B C  
T E F  
W O F  

Based on column 2, I would like to identify the duplicate rows to obtain the following file:

H I C  
W O F
M--
  • 25,431
  • 8
  • 61
  • 93
mf94
  • 439
  • 4
  • 19

2 Answers2

0

We can use duplicated

df1[!(duplicated(df1$col2)|duplicated(df1$col2, fromLast=TRUE)),]
#   col1 col2 col3
#3    H    I    C
#7    W    O    F
akrun
  • 874,273
  • 37
  • 540
  • 662
0

You can just compute which values occur exactly once and select those rows - like this:

Tab = table(df$V2)
Vals = unlist(attr(Tab, "dimnames"))[which(Tab == 1)]
df[df$V2 %in% Vals, ]
  V1 V2 V3
3  H  I  C
7  W  O  F
G5W
  • 36,531
  • 10
  • 47
  • 80