-1

I have a set of data looking like:

item    Group
1        a
2        b
3        a
4        a
5        b

and would like to have:

item    item    group
1        3        a
1        4        a
3        1        a
4        1        a
3        4        a
4        3        a
2        5        b
5        2        b

How best to solve? I'm working in Access and R.

Thanks,

Ghonima
  • 2,978
  • 2
  • 14
  • 23
  • What you are looking for is a called join in DBMS (join the similar table in this case) and though I have not much experience in R, look at the following link: https://stackoverflow.com/questions/1299871/how-to-join-merge-data-frames-inner-outer-left-right – Breakpoint Oct 07 '19 at 18:20

2 Answers2

0

First, separate your items into separate lists (arrays, etc).

List A = ( 1, 3, 4)
List B = ( 2, 5)

Then, identify all possible combinations of picking two items from each list.

List A Combinations = ( {1, 3}, {3, 1}, {1, 4}, {4, 1}, {3, 4}, {4, 3} )
List B Combinations = ( {2, 5}, {5, 2} )

Finally, generate a new output (file, or whatever you need) that lists each combination identified in the previous step next to the group that combination was generated from.

Eric J.
  • 147,927
  • 63
  • 340
  • 553
0

Following steps can be used to solve this problem.

  1. Iterate through initial set of data and store as key, value pair in array/list.
  2. loop through two nested loop. outter loop should iterate over step 1 generated array/list and Inner loop will again loop through initial set of data.
  3. if current (key, value) from outter loop got same group value but different (key, value) item then add this in another array/list.
  4. Finally after iterating through loops and inserting in second list/array we will have our desire results.
Shakil
  • 4,520
  • 3
  • 26
  • 36