title: R create a loop for a list of data frames
body: <p>I currently have a list which is made up of around 80+ data frames, what I would like to do is to loop a chunk of code for each individual data frame within the list, without naming each one individually, or splitting them into individual data frames to work on. </p>
  
  <p>Currently I split the list into each individual data frame using the below code:</p>
  
  <pre><code>dat5split &lt;- setNames(split(dat5, dat5$CODE), paste0("df", unique(dat5$CODE)))
  
  list2env(dat5split, globalenv())
  </code></pre>
  
  <p>I then work through each data frame individually: </p>
  
  <pre><code>    # call in SPC function and write to 'results10000'
  
      results10000&lt;-SPC_XBAR(df10000,vol_n,seasonality)
  
      results10000 = results10000 %&gt;%
        cbind(Spec = df10000$CODE) %&gt;%
        subset(`table_n` == 1)
  
      results10000 &lt;- results10000[order(results10000$tpd),]
  
      results10000$Date &lt;- as.Date(cbind(Date = df10000$CENSUS_DATE))
  
  # call in SPC function and write to 'results10001'
  
      results10001&lt;-SPC_XBAR(df10001,vol_n,seasonality)
  
      results10001 = results10001 %&gt;%
        cbind(Spec = df10001$CODE) %&gt;%
        subset(`table_n` == 1)
  
      results10001 &lt;- results10001[order(results10001$tpd),]
  
      results10001$Date &lt;- as.Date(cbind(Date = df10001$CENSUS_DATE))
  </code></pre>
  
  <p>Currently I call in the function 'SPC_XBAR' to where vol_n and seasonality are set earlier in the code. The script then passes the values to the function which then assigns the results to 'results10000, results10001' etc etc. Upon which I do a small bit of data wrangling on each newly created data frame before feeding the results back into sql server at the end. </p>
  
  <p>As you can see each one is being individually hard coded which is not efficient. </p>
  
  <p>What I would like to do is to loop a chunk of code for each individual data frame within the list, without naming each one individually. </p>
  
  <p>I believe a loop would solve this issue but I am a little inexperienced when it comes to the ability to create a loop around it. Any advice would be much appreciated.</p>
  
  <p>Cheers</p>