[R] Combinatorial problem

David Scott d.scott at auckland.ac.nz
Wed Aug 12 23:27:19 CEST 2009


Bernd Bischl wrote:
> Dimitris Rizopoulos wrote:
>> you could try something like the following:
>>
>> groups <- list(gp1 = 1:3, gp2 = 4:5, gp3 = 6:7,
>>                gp4 = 8:10, gp5 = 11)
>>
>> combn(5, 2, function (x) expand.grid(groups[x]), simplify = FALSE)
>> combn(5, 3, function (x) expand.grid(groups[x]), simplify = FALSE)
>> combn(5, 4, function (x) expand.grid(groups[x]), simplify = FALSE)
>>
> and this transforms it nicely into a single matrix
> 
> y <- combn(5, 2, function (x) as.matrix(expand.grid(groups[x])), 
> simplify = FALSE)
> Reduce(rbind, y)
> 
> 
> Bernd
>

This is absolutely, totally awesome guys. Thanks very much.

For the benefit of other readers, here is what happened.

I spent 10 minutes composing a question (tried to make it easy to set 
up). Went off and did some other emailing, decided to check R-help and 
there were two replies answering my question perfectly.

Thanks again

David Scott


_________________________________________________________________
David Scott	Department of Statistics
		The University of Auckland, PB 92019
		Auckland 1142,    NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email:	d.scott at auckland.ac.nz,  Fax: +64 9 373 7018

Director of Consulting, Department of Statistics




More information about the R-help mailing list