Dear R-Users, I need a matrix containing line by line all possible permutations with length 'i' of the integers 1:N, given the restriction that the integers in each row have to be in ascending order. For example: N = 5, length i = 3, should result in a matrix like this: 1 2 3 1 2 4 1 2 5 1 3 4 1 3 5 1 4 5 2 3 4 2 3 5 2 4 5 3 4 5 I'm grateful for any advice on how to proceed, Michel Lang
> help.search('combination') > ?combn > combn(1:5,3)[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1 1 1 1 1 1 2 2 2 3 [2,] 2 2 2 3 3 4 3 3 4 4 [3,] 3 4 5 4 5 5 4 5 5 5>On 1/30/07, michel lang <michellang at gmail.com> wrote:> Dear R-Users, > > I need a matrix containing line by line all possible permutations with > length 'i' of the integers 1:N, given the restriction that the > integers in each row have to be in ascending order. > > For example: N = 5, length i = 3, should result in a matrix like this: > 1 2 3 > 1 2 4 > 1 2 5 > 1 3 4 > 1 3 5 > 1 4 5 > 2 3 4 > 2 3 5 > 2 4 5 > 3 4 5 > > I'm grateful for any advice on how to proceed, > Michel Lang > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
Hi > library(gtools) > combinations(5,3) [,1] [,2] [,3] [1,] 1 2 3 [2,] 1 2 4 [3,] 1 2 5 [4,] 1 3 4 [5,] 1 3 5 [6,] 1 4 5 [7,] 2 3 4 [8,] 2 3 5 [9,] 2 4 5 [10,] 3 4 5 > On 30 Jan 2007, at 12:22, michel lang wrote:> Dear R-Users, > > I need a matrix containing line by line all possible permutations with > length 'i' of the integers 1:N, given the restriction that the > integers in each row have to be in ascending order. > > For example: N = 5, length i = 3, should result in a matrix like this: > 1 2 3 > 1 2 4 > 1 2 5 > 1 3 4 > 1 3 5 > 1 4 5 > 2 3 4 > 2 3 5 > 2 4 5 > 3 4 5 > > I'm grateful for any advice on how to proceed, > Michel Lang > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.-- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743