title: lapply function /loops on list of lists R
body: <p>I know this topic appeared on SO a few times, but the examples were often more complicated and I would like to have an answer (or set of possible solutions) to this simple situation. I am still wrapping my head around R and programming in general. So here I want to use <code>lapply</code> function or a simple loop to <code>data</code> list which is a list of three lists of vectors.</p>
  
  <pre><code>data1 &lt;- list(rnorm(100),rnorm(100),rnorm(100))
  data2 &lt;- list(rnorm(100),rnorm(100),rnorm(100))
  data3 &lt;- list(rnorm(100),rnorm(100),rnorm(100))
  
  data &lt;- list(data1,data2,data3)
  </code></pre>
  
  <p>Now, I want to obtain the list of means for each vector. The result would be a list of three elements (lists).</p>
  
  <p>I only know how to obtain list of outcomes for a list of vectors and </p>
  
  <pre><code>for (i in 1:length(data1)){
          means &lt;- lapply(data1,mean)
  }
  </code></pre>
  
  <p>or by:</p>
  
  <p><code>lapply(data1,mean)</code></p>
  
  <p>and I know how to get all the means using <code>rapply</code>:</p>
  
  <p><code>rapply(data,mean)</code></p>
  
  <p>The problem is that rapply does not maintain the list structure.
  Help and possibly some tips/explanations would be much appreciated.</p>