title: How to export output from a loop into a dataframe?
body: <p>I have generated some predicted values using a custom linear regression function, <code>reg()</code>, and iterating it over multiple variables with a for-loop. They are saved in <code>forage.pred</code>, a vector of more than 5000 values.</p>
  <p>I am now trying to convert this into a dataframe, but I don't know how to.</p>
  <p>Several loop tutorials that I found on the Internet use dummy example with one vector and index based on a single vector, so they don't apply to my situation.</p>
  <pre class="lang-r prettyprint-override"><code>forage
  # A tibble: 5,421 × 24
  #    year standid trt    plot sedge legume woody forbs
  #   &lt;dbl&gt;   &lt;dbl&gt; &lt;chr&gt; &lt;dbl&gt; &lt;dbl&gt;  &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
  # 1  1986       2 CCSP      1    30   14.4     0   30 
  # 2  1986       7 CCSP      1     0    0      20    0 
  # 3  1986      12 CCSP      1    18    0       0  158.
  # 4  1987       2 CCSP      1     2    0       0   32 
  # 5  1987       7 CCSP      1     0   40       0   80 
  # 6  1987      12 CCSP      1     0    2       0   52 
  # 7  1988       2 CCSP      1     0    2     424    2 
  # 8  1988       7 CCSP      1   104    0       0    0 
  # 9  1988      12 CCSP      1     4    4      64    2 
  # 10  1989       2 CCSP      1     0    0       0    2 
  # … with 5,411 more rows, and 16 more variables:
  #   panicum &lt;dbl&gt;, grass &lt;dbl&gt;, litter &lt;dbl&gt;,
  #   burned &lt;dbl&gt;, nonwoody &lt;dbl&gt;, pp_grow &lt;dbl&gt;,
  #   pp_watyear &lt;dbl&gt;, pp_spring &lt;dbl&gt;, pp_summer &lt;dbl&gt;,
  #   pp_winter &lt;dbl&gt;, pp_grow.s50 &lt;dbl&gt;,
  #   pp_grow.s30 &lt;dbl&gt;, pp_grow.s10 &lt;dbl&gt;,
  #   pp_grow.a10 &lt;dbl&gt;, pp_grow.a30 &lt;dbl&gt;, …
  # ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names
  
  yvar &lt;- forage[, 5:10]
  new.pp &lt;- forage[, 19:24]
  
  # Fit linear model and create predicted values
  reg &lt;- function(i, j) {
    lm.forage &lt;- lm(i ~ year + pp_grow,
                   data = forage)
    forage.pred &lt;- (predict(lm.forage,
                            newdata = list(pp_grow = j)))
    }
  
  # Loop this over multiple variables
  for (i in yvar) {
    for (j in new.pp) {
      reg(i, j)
    }
  }
  </code></pre>