title: R apply loop with return list
body: <p>I tried to replace <code>for</code> loop by <code>apply</code> loop in an existant R script. Nevertheless, my old function returns multiple dataFrames list like that <code>return(list(df1,df2))</code>. For some details, an example is presented below :  </p>
  
  <p>Old Script:</p>
  
  <pre><code>MyFunction = function(input){
    df1=array(NA,c(0,1))
    df2=array(NA,c(0,1))
    for(i in 1:n){
      ...
      df1 = rbind(df1,action1(input))
      df2 = rbind(df2,action2(input))
    }
  return(list(df1,df2))
  </code></pre>
  
  <p>New Script:</p>
  
  <pre><code>Object = do.call(rbind, lapply(1:n,function(i){
    df1 = action1(input)
    df2 = action2(input)
    return(list(df1,df2))
  }))
  </code></pre>
  
  <p>I obtain :</p>
  
  <pre><code>      [,1]   [,2]   [,3]   [,4]   [,5]  
   [1,] List,2 List,2 List,2 List,2 List,2
   [2,] List,2 List,2 List,2 List,2 List,2
   [3,] …
  </code></pre>
  
  <p>I have no idea to resolve my problem. Any help would be appreciate.</p>
  
  <p>Thanks in advances,</p>
  
  <p>B.Gees</p>