Dear all,
Is there a function that computes all binomial combinations.
I am aware of the function "choose(n, k)" which computes the
number of such combinations, but not the actual combinations
themselves, e.g.:
> choose(4, 2)
[1] 6
So I am looking for function that would give me the following
matrix as output, say:
> function(4, 2)
[,1] [,2]
[1,] 1 2
[2,] 1 3
[3,] 1 4
[4,] 2 3
[5,] 2 4
[6,] 3 4
Matlab has such function, but I could not find one in R.
Please also reply directly to me: mwolf at iew.uzh.ch.
Thanks much,
Michael
On Thu, 2007-11-22 at 19:09 +0100, Michael Wolf wrote:> Dear all, > > Is there a function that computes all binomial combinations. > I am aware of the function "choose(n, k)" which computes the > number of such combinations, but not the actual combinations > themselves, e.g.: > > > choose(4, 2) > [1] 6 > > So I am looking for function that would give me the following > matrix as output, say: > > > function(4, 2) > [,1] [,2] > [1,] 1 2 > [2,] 1 3 > [3,] 1 4 > [4,] 2 3 > [5,] 2 4 > [6,] 3 4 > > Matlab has such function, but I could not find one in R. > > Please also reply directly to me: mwolf at iew.uzh.ch. > > Thanks much, > MichaelUsing: help.search("combinations") leads you to several possibilities. For example:> combn(4, 2)[,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 1 1 2 2 3 [2,] 2 3 4 3 4 4 HTH, Marc Schwartz
t(combn(4,2)) in the package *combinat* produce this function. Xiaohui Michael Wolf wrote:> Dear all, > > Is there a function that computes all binomial combinations. > I am aware of the function "choose(n, k)" which computes the > number of such combinations, but not the actual combinations > themselves, e.g.: > > > choose(4, 2) > [1] 6 > > So I am looking for function that would give me the following > matrix as output, say: > > > function(4, 2) > [,1] [,2] > [1,] 1 2 > [2,] 1 3 > [3,] 1 4 > [4,] 2 3 > [5,] 2 4 > [6,] 3 4 > > Matlab has such function, but I could not find one in R. > > Please also reply directly to me: mwolf at iew.uzh.ch. > > Thanks much, > Michael > > ______________________________________________ > R-help at r-project.org 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. >