[R] generate combination set

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Fri Nov 16 14:34:51 CET 2007


Adrian Dusa wrote:
> On Thursday 15 November 2007, Bill.Venables at csiro.au wrote:
>   
>> Actually, (now that I know about combn), a better way is
>>
>> t(matrix(set[combn(7,2)], nrow = 2))
>>     
>
> Indeed, or to avoid transposing:
>
> matrix(set[combn(7,2)], ncol = 2, byrow=T)
>
> Adrian
>
>   
Or even (from someone who have known about combn for a while)

> combn(LETTERS[1:7], 2, paste, collapse="")
 [1] "AB" "AC" "AD" "AE" "AF" "AG" "BC" "BD" "BE" "BF" "BG" "CD" "CE"
"CF" "CG"
[16] "DE" "DF" "DG" "EF" "EG" "FG"



-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list