[R] Create unique sets of 3 from a vector of IDs?
dylan.beaudette at gmail.com
Wed Dec 3 04:46:35 CET 2008
On Tue, Dec 2, 2008 at 7:42 PM, philozine <philozine at yahoo.com> wrote:
> Dear all:
> 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
Does this do what you want?
expand.grid(letters[1:5], letters[1:5], letters[1:5])
> .... 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.
> Best regards,
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help