title: Forecast in list of lists
body: <p>I face a problem in forecasting time series in many subcategories.</p>
  
  <p>I have data in matrix of 10 variables and 19040 obseravtions.
  (variables:Product Category, subcategory, Group code, Year, Month, Units, Net sales)</p>
  
  <p>I've turned my matrix to a list in lists using this code.</p>
  
  <pre><code>        datar&lt;-aggregate(`Net Sales`~`01. Product Info 01.02 Subcategory    Year+Month,data=BESTDOCFORANALYSIS,FUN=sum)
  
  
         datal&lt;- datar[order(datar[,1],datar[,2]),]
  
         tskots&lt;-function(x){ts(x,end=c(2017,9),frequency=12)}
  
         ksts&lt;-tapply(datal$`Net Sales`,datal$`01.Product             Subcategory `,tskots)
  </code></pre>
  
  <p>I want to run a function in each subcategory.</p>
  
  <pre><code>            for(i in 1:60){
                fitarima[i]&lt;-auto.arima(ksts[i])
                fitets[i]&lt;-ets(ksts[i])
                 if (fitarima[i]$AIC&gt;=fitets[i]$AIC)
                           {fitmodel[i]&lt;-fitarima[i]}
                 else
                       {fitmodel[i]&lt;-fitets[i]}
                   k[i]&lt;-forecast(fitmodel[i],5)
                }  
  </code></pre>
  
  <p>in order to choose best model and  forecast for each subcategory.
  But i'm getting  this message</p>
  
  <p>Error in is.constant(x) : 
    (list) object cannot be coerced to type 'double'</p>
  
  <p>What you do propose to do?</p>