title: Store output of for loops in Dataframe R
body: <p>I am trying to store the results of two for loops in a dataframe.</p>
  
  <pre><code>    comp &lt;- c(mp, ct, n158, out)
      df &lt;- data.frame()
      for (i in length(comp)){
        lst &lt;- comp[i]
        d &lt;- data.frame()
        for (t in seq(1, sapply(lst, length))){
          ob &lt;- sapply(lst, function(m) m[t] ) 
          dt &lt;- train_data[(train_data$ADDR_POSTALCODE == as.numeric(ob)),]
          dt$AREA &lt;- names(lst)
          d &lt;- rbind(d, dt)
        }
        df &lt;- rbind(df, d)
      }
  </code></pre>
  
  <p>In my code, d and df contain the same values, because the results from the first loop are not concatenated. Comp is a list of 4</p>
  
  <pre><code>List of 4
   $ MP    : num [1:3] 94107 94110 94114
   $ Center: num [1:3] 94102 941103 941104
   $ 158   : num 94158
   $ Outer : num [1:4] 94112 94122 94132 94143
  </code></pre>
  
  <p>Df only contains the values for the last list "outer", but the loop should store the results for all four lists.
  Does anyone know where the mistake is, I just couldn't figure it out. Thanks in advance</p>