I'm new to R, yet keen to learn it.
I've just build a fairly complex system dynamics stocks and flow model I'd like to run using R's deSolve
package.
To simplify the problem. I'd like to make a sales forecast depending on the sales of the last 12 month. I used
movavg(ResultsSimulation$TotalSales, 12, type="s")
I considered that movavg
will use the last 12 values (1 time step = 1 month) for the calculation and therefore I would get the moving average over the last 12 month. Each time a different, deSolve
adds a time step.
Yet the Table "ResultsSimulation" and the column "TotalSales" doesn't exist in the beginning (as it is a result of the simulation)
I thought maybe I could trick R for the first run, creating a Table and column with the exact same name before running the simulation for the first time and the results after round 1 would override the first datatable so that from there on movavg
would use the simulation results. Apparently this doesn't work.
Do you have any suggestion how to compute a moving average over the values that still will be computed and saved in a list not available for the first time step?
Thanks for your help!