title: Adding a new column to each element in a list of tables or data frames
body: <p>I have a list of files. I also have a list of "names" which I <code>substr()</code> from the actual filenames of these files. I would like to add a new column to each of the files in the list. This column will contain the corresponding element in "names" repeated times the number of rows in the file. </p>
  
  <p>For example:</p>
  
  <pre><code>df1 &lt;- data.frame(x = 1:3, y=letters[1:3])
  df2 &lt;- data.frame(x = 4:6, y=letters[4:6])
  filelist &lt;- list(df1,df2)
  ID &lt;- c("1A","IB")
  </code></pre>
  
  <p>Pseudocode</p>
  
  <pre><code>  for( i in length(filelist)){
  
         filelist[i]$SampleID &lt;- rep(ID[i],nrow(filelist[i])
  
    }
  </code></pre>
  
  <p>// basically create a new column in each of the dataframes in filelist, and fill the column with repeted corresponding values of ID</p>
  
  <p>my output should be like:</p>
  
  <p><code>filelist[1]</code> should be:</p>
  
  <pre><code>   x y SAmpleID
   1 1 a       1A
   2 2 b       1A
   3 3 c       1A
  </code></pre>
  
  <p><code>fileList[2]</code></p>
  
  <pre><code>   x y SampleID
   1 4 d       IB
   2 5 e       IB
   3 6 f       IB
  </code></pre>
  
  <p>and so on.....</p>
  
  <p>Any Idea how it could be done. </p>