title: How to rename sub-elements of a list using lapply?
body: <p>After some manipulation, I have a list with the following elements:</p>
  <pre><code>$default
     a      b      c      d      e 
   1e-05  1e-02  1e-02  0e+00  0e+00 
  
  $`1`
       a                                 d          e
     0.00001   35.62987 4252.45832    0.00000    0.00000 
  
  $`2`
       a                                 d          e
     0.00001   35.62987 4252.45832    0.00000    0.00000 
  </code></pre>
  <p>The list can be reproduced with:</p>
  <pre><code>list1 &lt;- list(&quot;default&quot; = c(&quot;a&quot; = 0.00001, &quot;b&quot; = 0.01, &quot;c&quot; = .01, &quot;d&quot;=0, &quot;e&quot;=0),
                              &quot;1&quot; = c(&quot;a&quot; = 0.00001, 35.62987, 4252.45832, &quot;d&quot;=0, &quot;e&quot;=0),
                &quot;2&quot; = c(&quot;a&quot; = 0.00001, 35.62987, 4252.45832, &quot;d&quot;=0, &quot;e&quot;=0))
  </code></pre>
  <p>I'd like to quickly rename the elements of &quot;1&quot; and &quot;2&quot; to have the same names as the elements of the &quot;standard&quot; element i.e. &quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e.&quot;</p>
  <p>But when I use lapply to reassign names, the elements of the list are lost.  When I do:</p>
  <pre><code>lapply(list1, function(x) names(x) &lt;- c(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;))
  </code></pre>
  <p>I get:</p>
  <pre><code>$default
  [1] &quot;a&quot;    &quot;b&quot;      &quot;c&quot;      &quot;d&quot;    &quot;e&quot;
  
  $`1`
  [1] &quot;&quot;a&quot;    &quot;b&quot;      &quot;c&quot;      &quot;d&quot;    &quot;e&quot;
  
  $`2`
  [1] &quot;a&quot;    &quot;b&quot;      &quot;c&quot;      &quot;d&quot;    &quot;e&quot;
  </code></pre>
  <p>such that all the actual values are lost.  Is there a better way to do renaming across list elements?</p>