title: bind many data frames adding a column with their id
body: <p>I have many data frames named repeatably:</p>
  
  <pre><code>df.1 &lt;- data.frame("x"=c(1,2), "y"=2)
  df.2 &lt;- data.frame("x"=c(2,4), "y"=4)
  df.3 &lt;- data.frame("x"=2, "y"=c(4,5))
  </code></pre>
  
  <p>All data frames have the same number of rows and columns.
  I want to bind them, adding a column with the id of the data frame. The id would be the name of the source data frame.</p>
  
  <p>I know I could do this manually:</p>
  
  <pre><code>rbind(data.frame(id = "df.1", df.1),
        data.frame(id = "df.2", df.2),
        data.frame(id = "df.3", df.3))
  </code></pre>
  
  <p>But there's a lot of them and their number will change in the future.</p>
  
  <p>I tried writing for loops but they didn't work. I suppose that's because I'm basing them on a list of strings containing data frames' names rather than a list of data frames themselves.</p>
  
  <pre><code>df_names &lt;- ls(pattern = "df.\\d+")
  
  for (i in df_names) {
    i$id &lt;- i
    i
  }
  </code></pre>
  
  <p>...but I also haven't found any automated way of creating a list of data frames with repeatable names. And even if I do, I'm not that sure the for-loop above would work :)</p>