Dataframe (df1) has a column with variable of interest (V1), some of these values in that column correspond to column names in other data frame (df2).
I would need to find an overlap between values (rows) of that column in df1 and all the columns in df2.
head(df1)
V1 CHR MAPINFO Pval
a 2 38067017 0.27
c 2 38070880 0.29
d 2 38073394 0.00
e 2 38073443 0.00
f 2 38073564 0.01
head(df2)
a b c d f
-0.09 -0.08 -0.50 0.50 0.35
0.00 0.00 0.40 -0.40 -0.85
0.32 0.30 0.20 0.74 0.42
-0.41 -0.52 -0.72 -0.90 -0.96
1.30 1.30 1.10 1.10 1.20
-1.12 -1.78 -1.40 1.40 1.20
For example, in the df2, there is no "e" and in df1 there is no "b". How could I only keep the ones that are present both in df1$V1 and all columns of df2?
In the end I would need intersect between both dataframes (values present only in both).
head(df1)
V1 CHR MAPINFO Pval
a 2 38067017 0.27
c 2 38070880 0.29
d 2 38073394 0.00
f 2 38073564 0.01
head(df2)
a c d f
-0.09 -0.50 0.50 0.35
0.00 0.40 -0.40 -0.85
0.32 0.20 0.74 0.42
-0.41 -0.72 -0.90 -0.96
1.30 1.10 1.10 1.20
-1.12 -1.40 1.40 1.20
Since the real number of these columns is > ~1200, I can not filter one by one.
Is there another elegant way other than transpose?