I need to get all combinations for which the sum equal 100 using 8 variables that could take any value from 0 to 100 by incremental step of 10. (i.e. 0, 10, 20 ... 100)
The following script does just that but is very inefficient as it creates a huge dataset and I was wondering if someone had a better way of doing this.
x <- expand.grid("ON" = seq (0,100,10),
"3M" = seq(0,100,10),
"6M" = seq(0,100,10),
"1Y" = seq(0,100,10),
"2Y" = seq(0,100,10),
"5Y" = seq(0,100,10),
"10Y" = seq(0,100,10),
"15Y" = seq(0,100,10))
x <- x[rowSums(x)==100,]
Edit --
to answer the question from Stéphane Laurent
the result should look like
ON 3M 6M 1Y 2Y 5Y 10Y 15Y
100 0 0 0 0 0 0 0
90 10 0 0 0 0 0 0
80 20 0 0 0 0 0 0
70 30 0 0 0 0 0 0
60 40 0 0 0 0 0 0
50 50 0 0 0 0 0 0
(...)
0 0 0 0 0 0 10 90
0 0 0 0 0 0 0 100
expand.grid
' answer here relevant? – Quack