[R] All combination

Dimitris Rizopoulos d.rizopoulos at erasmusmc.nl
Fri Nov 13 10:09:47 CET 2009


have a look at function permutations from package 'e1071', e.g.,

library(e1071)
permutations(3)


I hope it helps.

Best,
Dimitris


RON70 wrote:
> Please consider the following :
> 
>> expand.grid(rep(list(c(1:3)), 3))
>    Var1 Var2 Var3
> 1     1    1    1
> 2     2    1    1
> 3     3    1    1
> 4     1    2    1
> 5     2    2    1
> 6     3    2    1
> 7     1    3    1
> 8     2    3    1
> 9     3    3    1
> 10    1    1    2
> 11    2    1    2
> 12    3    1    2
> 13    1    2    2
> 14    2    2    2
> 15    3    2    2
> 16    1    3    2
> 17    2    3    2
> 18    3    3    2
> 19    1    1    3
> 20    2    1    3
> 21    3    1    3
> 22    1    2    3
> 23    2    2    3
> 24    3    2    3
> 25    1    3    3
> 26    2    3    3
> 27    3    3    3
> 
> 
> Now I want to remove the rows which has any repetition of number. For
> example I want to remove row 1-5 but not 6 and so on........
> 
> Is there any easy way to do that?
> 
> Thanks,

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014




More information about the R-help mailing list