Time-Based Rolling Sum

tbr_sum(.tbl, x, tcolumn, unit = "years", n, na.rm = FALSE)

Arguments

.tbl

a data frame with at least two variables; time column formatted as date, date/time and value column.

x

column containing the values to calculate the sum.

tcolumn

formatted time column.

unit

character, one of "years", "months", "weeks", "days", "hours", "minutes", "seconds"

n

numeric, describing the length of the time window.

na.rm

logical. Should missing values be removed?

Value

dataframe with column for the rolling sum.

See also

Examples

tbr_sum(Dissolved_Oxygen, x = Average_DO, tcolumn = Date, unit = "years", n =
5)
#> # A tibble: 236 × 7
#>    Station_ID Date       Param_Code Param_Desc           Average_DO Min_DO   sum
#>         <int> <date>     <chr>      <chr>                     <dbl>  <dbl> <dbl>
#>  1      12515 2000-01-03 00300      OXYGEN, DISSOLVED (…       6.19   6.19  6.19
#>  2      12515 2000-03-14 00300      OXYGEN, DISSOLVED (…       6.7    6.7  20.2 
#>  3      12517 2000-03-14 00300      OXYGEN, DISSOLVED (…       7.3    7.3  20.2 
#>  4      12515 2000-03-16 00300      OXYGEN, DISSOLVED (…       6.41   6.41 26.6 
#>  5      12515 2000-05-03 00300      OXYGEN, DISSOLVED (…       4.42   4.42 31.0 
#>  6      12517 2000-06-14 00300      OXYGEN, DISSOLVED (…       5.74   5.74 36.8 
#>  7      12515 2000-06-15 00300      OXYGEN, DISSOLVED (…       4.86   4.86 41.6 
#>  8      12515 2000-07-11 00300      OXYGEN, DISSOLVED (…       4.48   4.48 46.1 
#>  9      12515 2000-09-12 00300      OXYGEN, DISSOLVED (…       5.64   5.64 51.7 
#> 10      12517 2000-10-17 00300      OXYGEN, DISSOLVED (…       7.96   7.96 59.7 
#> # … with 226 more rows