2015-11-03 116 views
0

如何ř生成排列如下:排列組合中的R

  • 號碼被使用的是1,2,5和10
  • 組合應當基於2個數字
  • 順序組合的是並不重要

針對上述情況,這導致:

1- 1, 2 
2- 1, 5 
3- 1, 10 
4- 2, 5 
5- 2, 10 
6- 5, 10 
+2

是組合2 4(不排列) – jogo

回答

3

使用combn

combn(c(1,2,5,10),2) # before the comma is your values to be used, after is the number of elements to be chosen 
    [,1] [,2] [,3] [,4] [,5] [,6] 
[1,] 1 1 1 2 2 5 
[2,] 2 5 10 5 10 10 
+0

非常感謝! – patfee

+0

@patfee如果您滿意,請接受etiennes的回答。讓別人花時間在你的問題上。 – Heroka