title: dplyr mutate formula referencing previous rows
body: <p>I have a df of rainfall that looks like this:</p>
  <pre><code># A tibble: 270,900 x 3
     Sample.Date Gauge  Rainfall
     &lt;date&gt;      &lt;fct&gt;     &lt;dbl&gt;
   1 2016-02-01  563061        0
   2 2016-02-01  563064        0
   3 2016-02-01  563065        0
   4 2016-02-01  563069        0
   5 2016-02-01  563070        0
   6 2016-02-01  563083        0
   7 2016-02-01  563090        0
   8 2016-02-01  563146        0
   9 2016-02-01  563149        0
  10 2016-02-01  566008        0
  # ... with 270,890 more rows
  </code></pre>
  <p>I have about 134 rain gauges and daily rainfall data for each of them.</p>
  <p>What I want to do is create a new column for each gauge to make a calculation, based on the previous day's calculation. Something along the lines of:</p>
  <pre><code>df %&gt;%
  group_by(Gauge) %&gt;%
  mutate(Rain_Calc = if_else(Sample.Date == &quot;2016-01-02&quot;, &quot;1.0&quot;, &quot;&quot;) %&gt;% #set Rain_Calc for Day 1
  mutate(Rain_Calc = 0.7 * (Rainfall + Rain_Calc(Previous Day))
  </code></pre>
  <p>My df starts on 02/01/2016. I want the Rain_Calc value on that day (for all gauges) to equal 1.0.</p>
  <p>Then, I want to calculate the &quot;Rain Calc&quot; values for the rest of the days which runs down the list (in sequential date order) and performs the calculation. I also need it grouped by Gauge.</p>
  <p>How could I possibly achieve this?</p>