I have a dataframe with 187 pairs of items across two variables, some of which are repeated. I want to create a new dataframe that pairs each item in the first variable with each item in the second (including repetitions), essentially creating a DF with 187*187 items. So I want every item in variable A to co-occur with every item in variable B. Each item will therefore be repeated 187 times.
I think I need to use a for-loop
but I'm not sure how to approach it.
As an example, take the data mydf
:
library(tibble)
mydf <- tribble(~GroupA, ~GroupB,
"A", "X",
"B", "Y",
"C", "Z")
I want to create something that looks like this:
GroupA GroupB
A X
A Y
A Z
B X
B Y
B Z
C X
C Y
C Z
Is there a simple way of doing this?