title: R - Add columns to dataframes in list by looping through elements in a vector
body: <p>I am working with several datasets that measure the same variables over many years. I am trying to add a year variable to each dataset, but more generally I want to loop through elements in a vector and add each as a new column in a list of dataframes. This question was similar to mine but I want to iteratively add each element in a vector to the corresponding dataframe as a new column:
  <a href="https://stackoverflow.com/questions/37523158/r-new-variables-over-several-data-frames-in-a-loop?rq=1">R - New variables over several data frames in a loop</a></p>
  
  <p>Here's sample data:</p>
  
  <pre><code>year &lt;- c(1:3)
  data1 &lt;- data.frame(var1 = c(1:5))
  data2 &lt;- data.frame(var1 = c(11:15))
  data3 &lt;- data.frame(var1 = c(21:25))
  data_list &lt;- list(data1 = data1, data2 = data2, data3 = data3)
  </code></pre>
  
  <p>I want to do this but think there's probably some way to loop (or lapply) that I haven't been able to figure out yet:</p>
  
  <pre><code>data1$year &lt;- year[1]
  data2$year &lt;- year[2]
  data3$year &lt;- year[3]
  </code></pre>
  
  <p>Since I have many years and datasets to work with, it'd be great to have a more efficient solution. Thanks!</p>