[R] Create unique sets of 3 from a vector of IDs?
philozine at yahoo.com
Wed Dec 3 04:42:25 CET 2008
This is one of those "should be easy" problems that I'm having great difficulty solving. I have a vector containing ID codes, and I need to generate a 3-column matrix that contains all possible combinations of three.
For example, my ID vector looks like this:
I need to generate a matrix that looks like this:
A B C
A B D
A B E
A C B
A C D
A C E
A D B
A D C
A D E
.... and so on. (Yes, this could yield some very large matrices!) It's totally fine, though less desirable, if the resulting matrix contains combinations with "duplicates," e.g., A A A, A A B, or whatever.
Thoughts? I'm pretty much stumped here. Thanks in advance for any help you can offer.
More information about the R-help