title: How to get the name of each element of a list using lapply()?
body: <p>Imagine that I have the following list </p>
  
  <pre><code>&gt; test &lt;- list("a" = 1, "b" = 2)
  </code></pre>
  
  <p>Each element of the list has a name : </p>
  
  <pre><code>&gt; names(test)
  </code></pre>
  
  <p>Now, I want to extract that name using <code>lapply()</code> because I want to use it in a new function which will be called using lapply. I just don't know how to extract the name of each element. </p>
  
  <p>I've tried using <code>deparse()</code> and <code>substitute()</code> but the outcome is weird : </p>
  
  <pre><code>&gt; lapply(test, function(x) {deparse(substitute(x))})
  $a
  [1] "X[[i]]"
  
  $b
  [1] "X[[i]]"
  </code></pre>
  
  <p>Does anyone has a clue ?</p>
  
  <h2>Precision :</h2>
  
  <p>I want to do something like this : 
  I have a list which is like test : </p>
  
  <pre><code>&gt; test &lt;- list("a" = matrix(1, ncol = 3), "b" = matrix(2, ncol = 3))
  </code></pre>
  
  <p>I want to apply a function to that list which transform the data inside each element and give a specific name for each column : </p>
  
  <pre><code>make_df &lt;- function(x) {
    output &lt;- data.frame(x)
    names(output) &lt;- c("items", "type", NAME_OF_X)
    return(output)
  }
  lapply(test, make_df)
  </code></pre>
  
  <p>The expected output is : </p>
  
  <pre><code>&gt; test
  $a
       [,1] [,2] [,3]
  [1,]    1    1    1
  attr(,"names")
  [1] "index" "type"  "a"    
  
  $b
       [,1] [,2] [,3]
  [1,]    2    2    2
  attr(,"names")
  [1] "index" "type"  "b"    
  </code></pre>
  
  <p>I don't know how I can get the name of the element to give a name to my third column.</p>