title: Return the names of data frames from a loop into a new data frame as IDs
body: <p>Suppose I have multiple data frames with the same prefixes and same structure.</p>
  <pre><code>mydf_1 &lt;- data.frame('fruit' = 'apples', 'n' = 2)
  mydf_2 &lt;- data.frame('fruit' = 'pears', 'n' = 0)
  mydf_3 &lt;- data.frame('fruit' = 'oranges', 'n' = 3)
  </code></pre>
  <p>I have a for-loop that grabs all the tables with this prefix, and appends those that match a certain condition.</p>
  <pre><code>res &lt;- data.frame()
  
  for(i in mget(apropos(&quot;^mydf_&quot;), envir = .GlobalEnv)){
    
    if(sum(i$n) &gt; 0){
      res &lt;- rbind.data.frame(res, data.frame('name' = paste0(i[1]),
                                              'n' = sum(i$n)))
    }
  }
  
  res
  </code></pre>
  <p>This works fine, but I want my 'res' table to identify the name of the original data frame itself in the 'name' column, instead of the column name. <strong>My desired result is</strong>:</p>
  <p><a href="https://i.stack.imgur.com/hYGyT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hYGyT.png" alt="enter image description here" /></a></p>
  <p>The closest I have gotten to solving this issue is:</p>
  <pre><code>'name' = paste0(substitute(i))
  </code></pre>
  <p>instead of</p>
  <pre><code>'name' = paste0(i[1])
  </code></pre>
  <p>but it just returns 'i'.</p>
  <p>Any simple solution? Base preferred but not essential.</p>