R如何生成排列如下:
对于上述情况,结果如下:
1- 1, 2
2- 1, 5
3- 1, 10
4- 2, 5
5- 2, 10
6- 5, 10
答案 0 :(得分: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