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--
  • 20,766
  • 7
  • 52
  • 87
mf94
  • 419
  • 4
  • 17

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
  • 789,025
  • 32
  • 460
  • 575
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
  • 34,378
  • 10
  • 39
  • 71