Ok so I have an excel sheet with a variety of scenarios and values, and what I'd like to do is transform some of those values by using a random distribution. I'm able to do that one scenario at at time, but I'd like to be able to do it in a more compact way, possibly with the apply function family. Here is a small version of my matrix which I use as a data.table with setDT:
matrixfromexcel =
Scenario char num1 num2 num3 val1 val2 val3
1 1 0 4 8 1.22 2.31 7.33
1 1 0 4 8 1.22 2.31 7.33
1 1 0 4 8 1.22 2.31 7.33
1 1 0 4 8 1.22 2.31 7.33
1 1 0 4 8 1.22 2.31 7.33
1 1 0 4 8 1.22 2.31 7.33
1 1 0 4 8 1.22 2.31 7.33
1 1 0 4 8 1.22 2.31 7.33
2 5 2 0 1 4.2 5.011 12.542
2 5 2 0 1 4.2 5.011 12.542
2 5 2 0 1 4.2 5.011 12.542
2 5 2 0 1 4.2 5.011 12.542
2 5 2 0 1 4.2 5.011 12.542
2 5 2 0 1 4.2 5.011 12.542
2 5 2 0 1 4.2 5.011 12.542
2 5 2 0 1 4.2 5.011 12.542
...
1200 66 8 1 0 555 120 1700
So as you can see, the scenario number separates the values into groups, and there is a large number of scenarios, up to 1000's+. Here is what I've used in order to add random numbers from a normally distributed function to the values of one column of one scenario:
matrixfromexcel[Scenario == 1, val1 := val1+rnorm(8, 1.22, 1)]
Where 8 is the number of different random numbers, 1.22 is the value I want the mean centered at, and 1 is the # of standard deviations I want in the random numbers.
So if I wanted to loop around from Scenario 1 to 1000, should I try an apply function or just try to use a loop? If apply function, could you show me your suggestion? Thank you