title: calculate a the maximum value in the previouc period in r
body: <p>I have a data frame with daily river levels, i want to select the maximum river height in a period two and three weeks prior to a date. When i use sum it the value is calculated, but if i change the function to max, i get an error
  '1: Problem while computing <code>A4260510_lag_2wk = map_dbl(...)</code>.
  i no non-missing arguments to max; returning -Inf'</p>
  <p>Date           A4260510    A4260512
  1998-01-01        1           2.1
  1998-01-02        1.2         2.2
  1998-01-03        1.1         2.3
  1998-01-04        1           2.2</p>
  <p>'''River_levels &lt;- River_levels %&gt;%   mutate(A4260510_lag_2wk = map_dbl(1:n(), ~ max(River_levels$A4260510[(Date &gt;= (Date[.] - days(20))) &amp; (Date &lt; Date[.]- days(7))], na.rm = TRUE))) %&gt;%
  mutate(A4260512_lag_2wk = map_dbl(1:n(), ~ max(River_levels$A4260512[(Date &gt;= (Date[.] - days(20))) &amp; (Date &lt; Date[.]- days(7))], na.rm = TRUE))) %&gt;%
  mutate(A4260513_lag_2wk = map_dbl(1:n(), ~ max(River_levels$A4260513[(Date &gt;= (Date[.] - days(20))) &amp; (Date &lt; Date[.]- days(7))], na.rm = TRUE))) %&gt;%
  mutate(A4260514_lag_2wk = map_dbl(1:n(), ~ max(River_levels$A4260514[(Date &gt;= (Date[.] - days(20))) &amp; (Date &lt; Date[.]- days(7))], na.rm = TRUE))) %&gt;%
  mutate(A4260515_lag_2wk = map_dbl(1:n(), ~ max(River_levels$A4260515 [(Date &gt;= (Date[.] - days(20))) &amp; (Date &lt; Date[.]- days(7))], na.rm = TRUE))) %&gt;%
  mutate(A4260516_lag_2wk = map_dbl(1:n(), ~ max(River_levels$A4260516[(Date &gt;= (Date[.] - days(20))) &amp; (Date &lt; Date[.]- days(7))], na.rm = TRUE))) %&gt;%
  mutate(A4260517_lag_2wk = map_dbl(1:n(), ~ max(River_levels$A4260517[(Date &gt;= (Date[.] - days(20))) &amp; (Date &lt; Date[.]- days(7))], na.rm = TRUE))) %&gt;%
  mutate(A4260518_lag_2wk = map_dbl(1:n(), ~ max(River_levels$A4260518[(Date &gt;= (Date[.] - days(20))) &amp; (Date &lt; Date[.]- days(7))], na.rm = TRUE))) %&gt;%
  mutate(A4260519lag_2wk = map_dbl(1:n(), ~ max(River_levels$A4260519[(Date &gt;= (Date[.] - days(20))) &amp; (Date &lt; Date[.]- days(7))], na.rm = TRUE))) '''</p>