title: Run a for loop over a list, save each list object in output matrix
body: <p>I want to run a for loop over a list. I have 3 questions:</p>
  <ol>
  <li>I wonder how I select  each list in &quot;i in 1:list&quot;, when doing the same for a data frame it can be for(i in 1:ncol(df)), but how should this be written for a list?</li>
  <li>I also wonder how I could &quot;add on&quot; the values for each loop to the &quot; output&quot; matrix?</li>
  <li>How to convert a list to a data frame. When doing it like data.frame(df3) they will be added column wise, number of rows will always be 3.</li>
  </ol>
  <p>Many thanks if someone has suggestions!</p>
  <pre><code>    name &lt;- rep(&quot;gg&quot;,3) 
  id &lt;- LETTERS[1:3]
  emmeans &lt;- runif(1:3)
  SE &lt;- runif(1:3)
  p &lt;- rep(c(0.001),3)
  df &lt;- data.frame(name,id, emmeans,p)
  df
  df  &lt;- list(df)
  
  name &lt;- rep(&quot;ff&quot;,3) 
  id &lt;- LETTERS[1:3]
  emmeans &lt;- runif(1:3)
  SE &lt;- runif(1:3)
  p &lt;- rep(c(0.003),3)
  
  df2 &lt;- data.frame(name,id, emmeans,p)
  df2 &lt;- list(df2)
  
  df3 &lt;- list(df,df2)
  df3
  &gt; df3
  [[1]]
  [[1]][[1]]
    name id   emmeans     p
  1   gg  A 0.2248491 0.001
  2   gg  B 0.4213938 0.001
  3   gg  C 0.3671521 0.001
  
  
  [[2]]
  [[2]][[1]]
    name id   emmeans     p
  1   ff  A 0.2561801 0.003
  2   ff  B 0.1705811 0.003
  3   ff  C 0.9714178 0.003
  
  output &lt;- matrix(nrow=2, ncol=5)
  
  for(i in 1:list){ # what could be written here?
    d &lt;- as.data.frame(df3[[i]])
    for(j in 1:nrow(d)){
      output[i,1] &lt;- d[1,3]
      output[i,2] &lt;- d[2,3]
      output[i,3] &lt;- d[3,3]
      output[i,4] &lt;- d[1,4]
      output[i,5] &lt;- d[1,1]
    }
  }
  
  #Wanted outcome:
  output
       [,1]                [,2]                [,3]                [,4]    [,5]
  [1,] &quot;0.224849119782448&quot; &quot;0.421393777942285&quot; &quot;0.367152112303302&quot; &quot;0.001&quot; &quot;gg&quot;
  [2,] &quot;0.256180095253512&quot; &quot;0.170581063022837&quot; &quot;0.971417842432857&quot; &quot;0.003&quot; &quot;ff&quot;
  </code></pre>