Skip to contents

This function takes a dataset prepared for mqo calculations and replaces the observation and modelled data columns with a rolling equivalent. Rolling values are calculated within groups of any categorical columns present in the data (likely the "pollutant" and "site" columns, along with any metadata).

Usage

mutate_rolling_mean(
  data,
  window_size = 8L,
  min_coverage = 0.75,
  progress = TRUE,
  dict = mqor::mqo_dict()
)

Arguments

data

An R data.frame containing at least five columns; a numeric column of observed values, a numeric column of modelled values, a character or factor column of identifiers that identify the site associated with the concentrations, a character or factor column of identifiers that identify the pollutant being measured/modelled, and a character or factor column containing just "fixed" or "indicative" to label each site. See demo_shortterm for an example format.

window_size

Integer vector giving rolling window size(s). This is the total number of included values. Defaults to 8L, which is the most useful for ozone statistics.

min_coverage

The minimum data coverage percent, expressed as a decimal (i.e., this option should be between 0 and 1, representing 0% and 100%).

progress

Show a progress bar? Passed to purrr::map().

dict

See mqo_dict() for more information. Acts as a data dictionary to specify the columns in the data {mqor} should use.

See also

openair::rollingMean() for a more flexible and performant version of mutate_rolling_mean().

Other data utilities: filter_year(), mqo_percentile(), summarise_daily(), validate_mod_obs_pairs()

Examples

# mock up some data that's long enough for an 8-hour rolling mean, then
# calculate
dplyr::tibble(
  date = ISOdate(2025, 1, 1, hour = 0:9),
  mod = rnorm(10, 10),
  obs = rnorm(10, 10),
  site = "A"
) |>
  mutate_rolling_mean()
#> # A tibble: 10 × 4
#>    date                  mod   obs site 
#>    <dttm>              <dbl> <dbl> <chr>
#>  1 2025-01-01 00:00:00 NA    NA    A    
#>  2 2025-01-01 01:00:00 NA    NA    A    
#>  3 2025-01-01 02:00:00 NA    NA    A    
#>  4 2025-01-01 03:00:00 NA    NA    A    
#>  5 2025-01-01 04:00:00 NA    NA    A    
#>  6 2025-01-01 05:00:00 NA    NA    A    
#>  7 2025-01-01 06:00:00 NA    NA    A    
#>  8 2025-01-01 07:00:00  9.91  9.82 A    
#>  9 2025-01-01 08:00:00 10.1   9.59 A    
#> 10 2025-01-01 09:00:00  9.74  9.91 A