First of all, please accept my apology for a poor title - i'm sure there could a better one, but I lack proper English / math terminology to phrase it the right way. I'm also pretty sure my problem is rather easy, but due to some basic math ignorance I don't even know how to call a decent google search.
I'm trying to find all possible combinations of items within pairs of columns.
Given a data frame like this:
data.frame(obj1 = c("A", "B", "C", "D", "E", "F"),
obj2 = c("B", "C", "D", "E", "F", "A"),
obj3 = c("C", "D", "E", "F", "A", "B"),
obj4 = c("D", "E", "F", "A", "B", "C"),
obj5 = c("E", "F", "A", "B", "C", "D"),
obj6 = c("F", "A", "B", "C", "D", "E"))
obj1 obj2 obj3 obj4 obj5 obj6
1 A B C D E F
2 B C D E F A
3 C D E F A B
4 D E F A B C
5 E F A B C D
6 F A B C D E
I'd like to add new rows in a way that for every pair of columns (obj1
-obj2
, obj1
-obj3
, obj1
-obj4
, ..., obj5
-obj6
) all combinations of items appear.
For example: in the 1st column pair: obj1
-obj2
, item A
appears only with item B
and F
. Other item level combinations are missing and that's what I want to get.
Caveats:
-each item (A,...,F) can appear only once within each row of the dataframe
-same letter pairs (of A-B and B-A) are treated as duplicates within a row, but not within a column
Effectively I'd like to grow this dataframe rowwise so that when a random pair of columns is picked, every combination of 6 items is present.
My gut tells me, that I'm looking at a 90 x 6 sized dataframe, but that's just intuition that i'm not able to put in a formula and explain how I came up with this number :)
If my question is not clear, the answer is obvious or in any other way violates any rule, please let me know, so I can try to explain myself
EDIT
After receiving all the comments i'll try to explain myself more clearly.
Consider this simple table of experimental conditions, let's call it table1 and treat it as a between subject table:
In this, simpler case, each participant will be presented with 6 pairs of target-items (A, B, C) taken from columns (col1, col2, col3) in the following way (table2 - within subject table):
Those 6 trials guarantee that for every participant within each pair every combination of target-items is present.
If I where to present 6 different traits (one per trial from table2) in a fixed order (for example: happy, sad, smart, bored, confused, tired) for every participant, after 3 participant each trait would be presented with regards to every combination of target-items.
For participant 1 - trait happy would be presented with targets A - B
For particiapnt 2 - trait happy would be presented with targets B - C
For particiapnt 3 - trait happy would be presented with targets C - A
NOTE that a (theoretical) set of B - A would be considered a duplicate.
What I'm looking for is a way of extending table1 from the above example of 3 items, into a 6 item table1. Naturally table2 will grow as well, but that's taken care of. Table1 is what is causing me problems.
This is how a starting point could look like
Thank you for any help. Best regards.