Reputation: 51
how can R generate permutations as follows:
for the above, this results in:
1- 1, 2
2- 1, 5
3- 1, 10
4- 2, 5
5- 2, 10
6- 5, 10
Upvotes: 0
Views: 124
Reputation: 3678
Use 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
Upvotes: 3