Time-Based Rolling Standard Deviation

tbr_sd(.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 standard deviation.

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

tibble with column for the rolling sd.

See also

Examples

tbr_sd(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     sd
#>         <int> <date>     <chr>      <chr>                    <dbl>  <dbl>  <dbl>
#>  1      12515 2000-01-03 00300      OXYGEN, DISSOLVED …       6.19   6.19 NA    
#>  2      12515 2000-03-14 00300      OXYGEN, DISSOLVED …       6.7    6.7   0.556
#>  3      12517 2000-03-14 00300      OXYGEN, DISSOLVED …       7.3    7.3   0.556
#>  4      12515 2000-03-16 00300      OXYGEN, DISSOLVED …       6.41   6.41  0.481
#>  5      12515 2000-05-03 00300      OXYGEN, DISSOLVED …       4.42   4.42  1.08 
#>  6      12517 2000-06-14 00300      OXYGEN, DISSOLVED …       5.74   5.74  0.985
#>  7      12515 2000-06-15 00300      OXYGEN, DISSOLVED …       4.86   4.86  1.02 
#>  8      12515 2000-07-11 00300      OXYGEN, DISSOLVED …       4.48   4.48  1.08 
#>  9      12515 2000-09-12 00300      OXYGEN, DISSOLVED …       5.64   5.64  1.01 
#> 10      12517 2000-10-17 00300      OXYGEN, DISSOLVED …       7.96   7.96  1.18 
#> # … with 226 more rows