title: For loop for forecasting several datasets at once in R
body: <p>I have a dataset with "Time, Region, Sales" variables and I want to forecast sales for each region using ARIMA or ETS(SES) using <code>library(forecast)</code>. There are a total of 70 regions and all of them have 152 observations each and (3 years of data). Something like this:</p>
  
  <pre><code>  Week      Region    Sales 
  01/1/2011      A       129
  07/1/2011      A       140
  14/1/2011      A       133
  21/1/2011      A       189
  ...           ...      ...
  01/12/2013     Z       324
  07/12/2013     Z       210
  14/12/2013     Z       155
  21/12/2013     Z       386
  28/12/2013     Z       266 
  </code></pre>
  
  <p>So, I want R to treat every region as a different dataset and perform an <code>auto.arima</code>. I am guessing a for loop should be an ideal fit here but I miserably failed with it. 
  What I would ideally want it to do is a for loop to run something like this (an auto arima for every 152 observations):</p>
  
  <pre><code>fit.A &lt;- auto.arima(data$Sales[1:152])  
  fit.B &lt;- auto.arima(data$Sales[153:304])
  ....
  fit.Z &lt;- auto.arima(data$Sales[10490:10640])
  </code></pre>
  
  <p>I came across <a href="http://robjhyndman.com/hyndsight/batch-forecasting/" rel="noreferrer">this</a> but while converting the dataframe into timeseries, all I got is NAs.</p>
  
  <p>Any help is appreciated! Thank you.</p>