title: R: Apply function to last level of nested list and keep name & structure
body: <pre><code>m &lt;- matrix(1:9, ncol=3)
  list1 &lt;- vector("list", 3)
  list1 &lt;- lapply(list1, function(x) x &lt;- m)
  list2 &lt;- vector("list", 3)
  list2 &lt;- lapply(list2, function(x) x &lt;- list1)
  list2
  </code></pre>
  
  <p>I would like to get an object with the same structure as <code>list2</code>, which contains the return of a  function of the matrix (in my case colMeans). This should work with up to n dimensions.</p>
  
  <p>I was playing around with nesting lapply, but it doesn't keep the names and I am sure somebody here knows a smarter way to do this.</p>
  
  <p>Thanks!</p>