Noah_Seagull
Noah_Seagull

Reputation: 377

How to select characters that are present in multiple columns of data

I am trying to select all the characters in this data set to make a data frame of only the character shared in common between the three columns

I tried using duplicated() from dyplr but that will only select duplicates from 2 of the columns.

#  UT          MT              HT
ABHD17C       ABCG1       AC005884.1
ABHD4         ABHD17C      AC009234.1
ABO           ABO         AC011933.1
AC009234.1    AC009234.1   AC097724.3
ACSL3        AC025627.9    ABO
ACSL5        AC097724.3    ACTA2
ACSS1        ACP5         ADAMTS15
ACTBP12      ACSS1        ADAMTS20
ACTG1        ACSL5        ADH7
ACTG1P12     ACSS1        AKR1C1
ACTN4        ACTA2        AKR1C2
ADAM19       ADAMTS15     AKR1C4
ADAMTS15     ADAMTS20     ALDH1L2
ADCK3        ADH7         ALDH3A1

In this example, the columns should only share "ABO", but in my more extensive data set characters are selected that are not in all three columns

Upvotes: 0

Views: 67

Answers (1)

G5W
G5W

Reputation: 37631

Actually, your data also has both "AC009234.1" and "ADAMTS15" in all three columns.

intersect(df$UT, intersect(df$MT, df$HT))
[1] "ABO"        "AC009234.1" "ADAMTS15" 

Upvotes: 1

Related Questions