Hello all,
I have a bit of a niche question for you all. Let's assume I have this dataframe:
df <- data.frame("X"=c("A","A","A","B","B","B","C","C","D","E","E"),"Y"=c(3,1,2,3,12,4,7,8,3,10,12))
X Y
A 3
A 1
A 2
B 3
B 12
B 4
C 7
C 8
D 3
E 10
E 12
Now, what I want to do is find which values are shared. As we can see, value 3 in column Y is shared with A,B, and D in column X. Additionally, value 12 in column Y is shared with B and E in column X.
C in column X does not contain any shared values.
I would like to now create a new dataframe with their complete intersections and values, and entries in column X are separated by underscore.
The resulting dataframe I want looks like this:
new_X new_Y
A_B_D_E 3
A_B_D_E 1
A_B_D_E 2
A_B_D_E 12
A_B_D_E 4
A_B_D_E 10
C 7
C 8
Thank you all in advance!