title: Problem in running for loop for estimation, prediction and forecast evaluation of rolling forecast origin
body: <p>I want to calculate the rolling forecast origin using the for loops that I have created.</p>
  <p>Firstly, I created a for loop in order to create a random walk forecast of the independent variables and store them as a list. Now, I want to estimate rolling regression and then I want to forecast them and store those models as a list. After that, my intention was to create another loop in order to extract t+1 from every created model and calculate RMSE for every vector.</p>
  <p>I have a problem with finishing the second for the loop and creating the third one in order to calculate RMSE values. </p>
  <p>If anyone has any time, I would appreciate your help. Thank you.</p>
  <p>Here is the code:</p>
  <pre><code>library(readxl)
  library(tidyverse)
  library(lubridate)
  library(fpp2)
  library(naniar)
  
  zalihe_input &lt;- read_excel(&quot;C:/Users/User/OneDrive/Radna površina/zalihe_input.xlsx&quot;)
  zalihe_input &lt;- zalihe_input %&gt;% 
    mutate(pcy_ii = 100 * (ii - lag(ii,4))/ lag(ii,4)* 100)
  View(zalihe_input) 
    
  #FORECASTING HORIZONT
  
  H &lt;- 8
  
  #LAST POINT OF ESTIMATION
  
  LP &lt;- 72
  
  #FORECAST UNTIL
  
  FU &lt;- zalihe_input %&gt;% 
    nrow() - 1
  
  #OUT-OF-SAMPLE FORECAST (FORECAST UNTIL), WHICH IS HERE 2021Q4 - 2017Q4
  
  OF &lt;- FU - LP - H
  
  #CREATING DATAFRAME FOR ACTUAL VALUES
  
  actual_values &lt;- data.frame() 
  
  #SETTING THE FORECASTING DATE
  
  actual_values &lt;- subset(zalihe_input, vrijeme &gt; &quot;2017Q4&quot; &amp; vrijeme &lt; &quot;2022Q1&quot;, select = vrijeme)
  
  #CREATING FOR LOOP FOR ROOLING OF ACTUAL VALUES
  
  for (i in 1:H){
    first &lt;- LP + i
    last &lt;- first + H
    actual_values[0 : H + i, i + 1] = zalihe_input$ii[first:last]
  }
  
  #FUNCTION FOR CALCULATING RMSE
  
  rmse &lt;- function(actual, pred) {
    sqrt(mean( (actual - pred) ^ 2))
  }
  
  #CORRELATION
  
  cor(zalihe_input$ii, zalihe_input$inv)
    
  #CREATING FOR LOOP FOR ESTIMATIONS AND FORECASTS OF LIN.REG./ARIMA MODELS
  
  list_df &lt;- list()
  model_rw_inv &lt;- list()
  model_rw_ex &lt;- list()
  model_rw_imp &lt;- list()
  model.rw &lt;- list()
  model.est &lt;- list()
  model.fore &lt;- list()
  
  for (i in 1:OF){
    list_df[[i]] &lt;- zalihe_input %&gt;%
      slice_head(n = (LP + i)) %&gt;% 
      select(vrijeme, ii, inv, ex, imp, pcy_ii) 
    
    model_rw_inv[[i]] &lt;- rwf(list_df[[i]][[&quot;inv&quot;]], h = H, drift = TRUE)
    model_rw_ex[[i]] &lt;- rwf(list_df[[i]][[&quot;ex&quot;]], h = H, drift = TRUE)
    model_rw_imp[[i]] &lt;- rwf(list_df[[i]][[&quot;imp&quot;]], h = H, drift = TRUE)
    
    #FORECASTING MODELS
    
    # forecast(model_rw_inv, newdata = list_df[[i]], h = H)$mean
    # forecast(model_rw_ex, newdata = list_df[[i]], h = H)
    # forecast(model_rw_imp, newdata = list_df[[i]], h = H)
  
  }
  
  #ESTIMATION OD MODELS
  
  for (i in 1:OF){
    list_df[[i]] &lt;- zalihe_input %&gt;%  
      slice_head(n = (LP + i - 1))
    
    #USING RW VALUES TO ESTIMATE AND FORECAST OUT-OF-SAMPLE ONE STEP AHEAD
    
    model.est[[i]] &lt;- lm(ii ~ inv + ex + imp, data = list_df[[i]])
    model_fore[[i]] &lt;- forecast(model_est[[i]], newdata = list_df[[i]], h = H)
  
  }
  
  #FOR LOOP FOR CALCULATING RMSE WITH T+1 FROM EVERY MODEL FORECAST 
  
  for (i in 1:H){
    horizont_fore[[i]] &lt;- model_fore[[i]][72 + i]
    for (j in 1:H){
      
    }
  }
  </code></pre>