-1

I am relatively new to R so any help on this would be much appreciated:

The problem is as follows: I have 5 groups of values called A, B, C, D, E. Each group contains 10 values. The values in group A are: a1, a2, a3, a4, a5, a6, a7, a8, a9, a10. The values in group B are: b1, b2, b3, b4 ... b10 and so on. I need to find all of the unique combinations of values possible where in each combination no two values come from the same group. Each combination must contain 5 values. I am not concerned with the order of values.

Thanks

Harry Daniels
  • 510
  • 1
  • 5
  • 15
  • See `?expand.grid`. Btw, if you're not more specific (e.g., with actual code), someone will probably read this as a dupe and close it. – Frank Apr 19 '17 at 16:32
  • Another few: http://stackoverflow.com/q/8108098/ http://stackoverflow.com/questions/11388359/unique-combination-of-all-elements-from-two-or-more-vectors http://stackoverflow.com/questions/18705153/generate-list-of-all-possible-combinations-of-elements-of-vector – Frank Apr 19 '17 at 16:35

1 Answers1

1

expand.grid(A,B,C,D,E) will produce a data frame containing each combination of elements from each of the five sets.

Andrew Gustar
  • 17,295
  • 1
  • 22
  • 32
  • Thanks so much, it's so much simpler than i could have imagined! I've been toying around with nested loops to no avail! – Harry Daniels Apr 19 '17 at 16:45
  • R is full of useful little functions that you only discover after doing things the hard way! SO is a great way of finding out about them, if you browse some random questions and answers. – Andrew Gustar Apr 19 '17 at 16:49