title: Function for Appending Rows to Data Frame Based on Previous Variable Values in R
body: <p>I'm trying to create a function that allows me to append rows to an existing data frame based on variables from the most previous row (immediately above), multiple times over. </p>
  
  <pre><code>#Here's what I'm starting with 
  
  Balance &lt;- c(25000)
  Pmt &lt;- c(1500)
  Interest &lt;- c(.05)
  DF &lt;- data.frame(Balance,Pmt,Interest)
  DF  
     Balance Pmt Interest
  1   25000 100     0.05
  </code></pre>
  
  <p>For example, I'd like to see the next 4 rows added where the "Balance" of the new row is equal to ((Balance-Pmt)*(1+Inerest)) of the previous row, and the "Pmt" and "Interest" rows stay constant. </p>
  
  <pre><code># Manually
  DF[2,1] &lt;- (DF[1,1] - DF[1,2])*(1+DF[1,3])
  DF[2,2] &lt;- DF[1,2]
  DF[2,3] &lt;- DF[1,3]
  D
    Balance  Pmt Interest
  1   25000 1500     0.05
  2   24675 1500     0.05
  </code></pre>
  
  <p>Obviously, I'd like to replicate this as many times, n, as I'd like without having to manually reference the previous row. I'd like a function that allows me to add rows to the data frame as many times as I'd like, following that same logic. Any help is appreciated!</p>