[R] Create unique sets of 3 from a vector of IDs?

G. Jay Kerns gkerns at ysu.edu
Wed Dec 3 05:41:07 CET 2008


Dear Brandon,

On Tue, Dec 2, 2008 at 10:46 PM, Dylan Beaudette
<dylan.beaudette at gmail.com> wrote:
> 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:
>> A
>> B
>> C
>> D
>> E
>>
>> 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
>
> Hi,
>
> Does this do what you want?
>
> expand.grid(letters[1:5], letters[1:5], letters[1:5])
>
>
> D
>


Have a look at urnsamples() in the prob package.

ID <- LETTERS[1:5]
urnsamples(ID, size = 3, replace = FALSE, ordered = FALSE)

Best,
Jay




***************************************************
G. Jay Kerns, Ph.D.
Associate Professor
Department of Mathematics & Statistics
Youngstown State University
Youngstown, OH 44555-0002 USA
Office: 1035 Cushwa Hall
Phone: (330) 941-3310 Office (voice mail)
-3302 Department
-3170 FAX
E-mail: gkerns at ysu.edu
http://www.cc.ysu.edu/~gjkerns/



More information about the R-help mailing list