title: Combining Forecasts Results into a Cohesive Data Frame in R
body: <h1>Loop to Compute and Store <code>auto.arima()</code> and <code>forecast()</code> Results in Dataframe</h1>
  
  <p>A small sample of my dataframe with random data can be generated with the following</p>
  
  <pre><code>df &lt;- data.frame(col1 = runif(24, 400, 700),
                    col2 = runif(24, 350, 600),
                    col3 = runif(24, 600, 940),
                    col4 = runif(24, 2000, 2600),
                    col5 = runif(24, 950, 1200))
  
  
  colnames(df) &lt;- c("NorthHampton to EastHartford", "NorthHampton to Edison", 
                    "NorthHampton to Yonkers", "North Hampton to Brooklyn", "NorthHampton to Rotterdam" )
  </code></pre>
  
  <p>I'm trying to run a series of <code>ARIMA</code> models using <code>auto.arima()</code> in R and having difficulty generating my output in the desired format. A sample section of where I had started is below.</p>
  
  <pre><code>ts &lt;- ts(df, frequency = 12, start = c(2014, 1), end = c(2015, 12))
  
  model  &lt;- list()
  results &lt;- list()
  
  
  for (i in 1:ncol(ts)) {
    fit &lt;- auto.arima(ts[,i], stepwise = F, approximation = F)
    model &lt;- forecast(fit)$method
    results &lt;- forecast(fit, h = 3)$mean
  
  #   print(forecast(fit)$method)
  #   print(forecast(fit, h=3)$mean)
  
    }
  </code></pre>
  
  <p>Ideally I want my loop to populate a <code>data.frame</code> that will be formatted like this:</p>
  
  <pre><code>Lane                                 Model                          Time    PointEstimate
  Northampton to East Hartford    "ARIMA(0,0,0) with non-zero mean"   Jan-16                  
  Northampton to East Hartford    "ARIMA(0,0,0) with non-zero mean"   Feb-16                  
  Northampton to East Hartford    "ARIMA(0,0,0) with non-zero mean"   Mar-16                  
  Northampton to Edison           "ARIMA(0,0,0) with non-zero mean"   Jan-16                  
  Northampton to Edison           "ARIMA(0,0,0) with non-zero mean"   Feb-16                  
  Northampton to Edison           "ARIMA(0,0,0) with non-zero mean"   Mar-16                  
  Northampton to Yonkers          "ARIMA(0,0,0) with non-zero mean"   Jan-16                  
  </code></pre>
  
  <p>The results for Column <code>Lane</code> should be the same as the column name from the original dataframe. The results for <code>Model</code> are the results from <code>forecast(fit)$method</code>, and the the Point Estimate should be the result of <code>forecast(fit, h = 3)$mean</code>, where each item is repeated in the <code>dataframe</code> <code>h times</code> (3) in this case. </p>
  
  <p>I think my loop is performing the calculations that I need I just can't figure out how to store the results, and then append the results for the next iteration through the end of the loop. I appreciate any help I can get on this.</p>