title: R + Data frame name as string variable
body: <p>I have a list of data frames, and I'm looking to assign to each data frame within the list a variable column that is simple a character vector of the given dataframe's  name.</p>
  
  <pre><code>data &lt;- list(
      d1 = data.frame(animal = sample(c("cat","dog","bird"), 5, replace = T)),
      d2 = data.frame(animal = sample(c("cat","dog","bird"), 5, replace = T)),
      d3 = data.frame(animal = sample(c("cat","dog","bird"), 5, replace = T))
  )
  </code></pre>
  
  <p>This yields: </p>
  
  <pre><code>&gt; data 
  $d1
    animal
  1    cat
  2   bird
  3    cat
  4    cat
  5    cat
  
  $d2
    animal
  1    dog
  2    cat
  3    cat
  4    cat
  5   bird
  
  $d3
    animal
  1    cat
  2    dog
  3    cat
  4    cat
  5    cat
  </code></pre>
  
  <p>What I want to do is create something like the following:</p>
  
  <pre><code>&gt; newdata 
  $d1
    animal newvar
  1    cat     d1
  2    cat     d1
  3    cat     d1
  4    dog     d1
  5    cat     d1
  
  $d2
    animal newvar
  1   bird     d2
  2    cat     d2
  3   bird     d2
  4    cat     d2
  5    cat     d2
  
  $d3
    animal newvar
  1   bird     d3
  2   bird     d3
  3    cat     d3
  4    cat     d3
  5   bird     d3
  </code></pre>
  
  <p>But I can't quite figure out how to actually reference the data frame name --in a list of data frames-- and turn it into a character vector appropriately. </p>
  
  <p>Something like the following does not work:</p>
  
  <pre><code>namefunc &lt;- function(x) {
      x &lt;- x %&gt;% transform(newvar = as.character(x))
  }
  
  newdata &lt;- namefunc(data)
  </code></pre>