[R] function for all binomial combinations?

Marc Schwartz marc_schwartz at comcast.net
Thu Nov 22 19:18:23 CET 2007


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,
> Michael

Using:

  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



More information about the R-help mailing list