Skip to contents

Running eight hours mean from hourly concentration values.

Usage

runningEightHoursMean(
  time = "time",
  value = "value",
  na.rm = FALSE,
  input = FALSE
)

Arguments

time

a date-time or date object of class POSIXct, POSIXlt.

value

a numeric vector with hourly concentrations of a pollutant.

na.rm

a logical value indicating whether NA values should be stripped before the computation proceeds.

input

a logical value indicating whether the inputs should be included in the result.

Value

A data.frame, data.table with time and corresponding running mean named as "r_time" and "r_value".

Details

This function computes the eight-hour running mean of a pollutant. Each eight-hour average so calculated is assigned to the day on which it ends. i.e. the first calculation period for any one day will be the period from 17:00 on the previous day to 01:00 on that day; the last calculation period for any one day will be the period from 16:00 to 24:00 on the day.

The result of this function can be used to compute the statistical indicator required by EU directive 2008/50 for O3, for the protection of human health, i.e. the maximum daily eight-hour mean concentration.

Note

The running mean operates on the physical order of input. One has to ensure that there are no gaps in input.

Examples

# Random data to simulate an O3 time series.
O3 <- runif(365 * 24) * 60
ts <- seq(lubridate::dmy_hm("1/1/2019 01:00"),
          lubridate::dmy_hm("1/1/2020 00:00"), by = "1 hour")
# Compute 8 hours running mean
rO3 <- runningEightHoursMean(time = ts, value = O3, na.rm = TRUE)
# Compute the maximum daily 8-hour mean concentration
rO3[, `:=`(maxDO3 = max(r_value, na.rm = TRUE)), by = .(lubridate::date(r_time))]
#>                    r_time  r_value   maxDO3
#>                    <POSc>    <num>    <num>
#>    1: 2019-01-01 08:00:00 38.18778 45.15363
#>    2: 2019-01-01 09:00:00 39.12800 45.15363
#>    3: 2019-01-01 10:00:00 44.75511 45.15363
#>    4: 2019-01-01 11:00:00 41.25854 45.15363
#>    5: 2019-01-01 12:00:00 43.02834 45.15363
#>   ---                                      
#> 8756: 2020-01-01 03:00:00       NA 23.64462
#> 8757: 2020-01-01 04:00:00       NA 23.64462
#> 8758: 2020-01-01 05:00:00       NA 23.64462
#> 8759: 2020-01-01 06:00:00       NA 23.64462
#> 8760: 2020-01-01 07:00:00       NA 23.64462