title: Dynamically create subsets in R with a for loop
body: <p>I am trying to create different subsets out of a table and with each iteration I want to shift one column upwards. So far I realized this with this code but undynamically:</p>
  <pre><code>subset_cor_lag00 &lt;- subset(data_24h, select = c(price_return, sentiment_return, tweet_return))
  korr_tab_lag00 &lt;- cor(subset_cor_lag00)
  
  subset_cor_lag01 &lt;- transform(subset_cor_lag00, price_return = lead(price_return))
  subset_cor_lag01 &lt;- na.omit(subset_cor_lag01)
  korr_tab_lag01 &lt;- cor(subset_cor_lag01)
  </code></pre>
  <p>But now I tried to do this dynamically but I got stuck with it. So maybe someone has a hint. I really would appreciate it. I tried this</p>
  <pre><code>for(i in 1:5) {
    paste0(&quot;subset_cor_lag0&quot;, i) &lt;- transform(paste0(&quot;subset_cor_lag0&quot;, i-1), price_return = lead(price_return))
    paste0(&quot;subset_cor_lag0&quot;, i) &lt;- na.omit(paste0(&quot;subset_cor_lag0&quot;, i))
    paste0(&quot;korr_tab_lag0&quot;, i) &lt;- cor(paste0(&quot;subset_cor_lag0&quot;, i))
  }
  </code></pre>