I think I ran into a situation that (to the best of my knowledge) is not fully covered by the awesome dplyr
library, so I guess it will need a bit more of coding than what I am capable of. I have the following 2 data frames:
df1 =
Col1 Col2 Col3
1 A 1 X
2 A 1 X
3 B 1 X
4 C 1 X
5 D 1 Y
6 D 1 Z
df2 =
Col1 Col2 Col3
1 A 2 X
2 B 2 Y
3 C 2 Y
4 G 2 Z
5 H 2 X
6 I 2 Z
I want only the rows which has common elements from Col1
only, this is:
out =
Col1 Col2 Col3
1 A 1 X
2 A 1 X
3 B 1 X
4 C 1 X
5 A 2 X
6 B 2 Y
7 C 2 Y
It looks like dplyr::intersect
would do it, but since Col2
and Col3
have different values, it gives me table with 0 values. Your guidance is much appreciated. Thanks. P. Perez.