-1

given a vector c(3,4,5) the length of vector is variable, i would return matrix of combination with all element less the value in the vector make like this:

 [x_1] [x_2] [x_3] 
[1,]  3    4     5
[2,]  2    4     5
[3,]  1    4     5 
[4,]  3    3     5
[5,]  3    2     5
[6,]  3    1     5
[7,]  2    3     5
[8,]  1    2     5
[9,]  1    4     4
[10,] 1    4     3
[11,] 1    4     2
..... 

this is only a part of all possible combination, but i would have all possible combination.

1 Answers1

1

I believe this is it.

x <- c(3, 4, 5)

lst <- lapply(x, ':', 1)
Map(expand.grid, list(lst))
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66