1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

組み合わせの数とパターンの列挙

Posted at

組み合わせ nCi  の列挙

gtools にはあるが,パッケージをインストールしなくても,Base には combn() がある。行と列が転置されている関係があるが, combn() は得られる組み合わせにおいて関数を適用することができる。

> library(gtools)
> committees = gtools::combinations(n=5,r=3)
> committees
      [,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

> combn(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
> # combn(x, m, FUN = NULL, simplify = TRUE, ...) 

組み合わせの数

定義により計算する必要はなく,Base には choose() がある(速い)。

> factorial(5)/(factorial(3)*factorial(2))
[1] 10
> choose(5, 3)
[1] 10
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?