0

I am currently developing a model to forecasts some data.

I am using the following process to output data from the process but I do not want to create excessive amounts of new data frames.

    for (i in 1:10) {
        print(i)
        assign(paste("run", i, sep = ""), d.frame)
        d.frame <- data.frame(seq(from = 0 + i, to = 2015 + i, by = 1))   
    }

I would like to export the data to 1 dataframe/table, but with multiple columns

Thanks in advance for any pointers

Edited to add.

I am training a model with 1 week + 1 Day of data (2016 + 288 data points) I am forecasting the results for the next so the next 288 points in the time series.

I am retraining the model for each time step so loop 1 uses data points 1 to 2016 and outputs 3 time steps forward loop 2 uses data points 2 to 2017 and outputs 3 time steps forward .. .. I would like to export the Model Paramaters for each loop into a dataframe

Loop, Alpha, Beta, Gamma
  1    0.04   0     0.50
  2    0.1    0     0.45
  3
  4

My second issue the same as above, to export the data from the time series forecasts

Forecast step   H1    H2    H3
      1         72    87    88
      2         84    90    95
      3         88    84    76
Stevieb143
  • 31
  • 1
  • 4
  • 1
    You are probably going to want to make [a list of data frames](https://stackoverflow.com/questions/17499013/how-do-i-make-a-list-of-data-frames) rather than create a bunch of variables with an index embedded in the name. But it's unclear to me exactly what the desired result is here. Show what you are trying to make. – MrFlick Feb 19 '18 at 19:25
  • Many thanks for the Reply. I am trying to run a process through a loop and then at the end of each loop I would like to store the outputs in a new column. so the new table structure would be Point, Loop1_results, Loop2_Results, ..... Loopn_Results. – Stevieb143 Feb 19 '18 at 19:51

2 Answers2

0

I'm sure there's a more elegant way than this, but I just wanted to quickly adapt your code to avoid using assign():

d.frame <- data.frame(run1 = seq(from = 0 + 1, to = 2015+1, by = 1))

for(i in 2:10){
  d.frame <- data.frame(d.frame, d.frame$run1 +i) 
  names(d.frame)[i] = paste0("run", i)
}
David Klotz
  • 2,206
  • 1
  • 5
  • 15
0

I think I have found a solution, it may be possible to use alternative methods that are more efficient.

nc <- 3
nr <- 10
df <- data.frame(matrix(NA, ncol = nc, nrow = nr))
for (i in seq_len(nr)) {
    ## can fill in the "cells" as he goes with various results 
    ## the below is just to illustrate 
    df[i, 1] <- speedforecast_All$model[3]
    df[i, 2] <- speedforecast_All$model[4]
    df[i, 3] <- speedforecast_All$model[5]
}
df
Stevieb143
  • 31
  • 1
  • 4