Skip to contents

Input data should be rOstluft::format_rolf() data.

Usage

summary_periodic(
  data,
  y = "value",
  groupings = grp("starttime_of_day"),
  fun = list("mean", "sd", "median", "mad", "percentile05", "percentile25",
    "percentile75", "percentile95"),
  fun.args = list(na.rm = TRUE),
  nmin = 3,
  coords = c(lat = 47.36667, lon = 8.55)
)

Arguments

data

a data.frame or tibble containing the data

y

a character string specifying the taget variable to be summarised, usually "value".

groupings

additional groupings. Use helper grp() to create; groupings must be from possible outcomes of cut_timeseries_periodic().

fun

function or list of functions for summary, can be named (then the outut stat is named after the function's name); Strings matching the regular expression /^percentile([0-9]){1,2}$/i are converted into the respective function. "percentile95" => function(x, ...) quantile(x, 95 / 100, ...)

fun.args

a list of extra arguments passed on to fun.

nmin

numeric, minimum number of values for fun, if n < nmin: NA is returned

coords

a named vector of the location in WGS84 coordinates for the daylight factoring. suncalc::getSunlightTimes() is used to calculate sunrise, sunset times. Default: c(lat = 47.36667, lon = 8.55) => Zuerich, Switzerland

Value

a tibble with summarised data

Computed variables

as determined by cut_timeseries_periodic() in combination with grouping

The names of the columns stay the same as in data.

  • factor columns according to the groups specified in grouping

  • factor column stat containing the name of the summarize function as level

  • column value with the result of the summarize function

  • n count of occurrences for the corresponding bin

  • freq frequency of the corresponding bin

Examples

fn <- rOstluft.data::f("Zch_Stampfenbachstrasse_2010-2014.csv")

data <-
  rOstluft::read_airmo_csv(fn) %>%
  rOstluft::pluck_parameter("NOx", "O3", "PM10") %>%
  rOstluft::resample(new_interval = "h1")

fun <- list(middle = "mean", middle2 = "median", ymin = "percentile05",
           lower = "percentile25", upper = "percentile75", ymax = "percentile95")

data_summarized <- summary_periodic(data, fun = fun)
data_summarized
#> # A tibble: 432 × 9
#>    starttime_of_day site        parameter interval unit      n  freq stat  value
#>    <ord>            <fct>       <fct>     <fct>    <fct> <int> <dbl> <fct> <dbl>
#>  1 00:00            Zch_Stampf… NOx       h1       ppb    1826 0.333 midd… 24.0 
#>  2 00:00            Zch_Stampf… NOx       h1       ppb    1826 0.333 midd… 17.1 
#>  3 00:00            Zch_Stampf… NOx       h1       ppb    1826 0.333 ymin   4.07
#>  4 00:00            Zch_Stampf… NOx       h1       ppb    1826 0.333 lower  9.05
#>  5 00:00            Zch_Stampf… NOx       h1       ppb    1826 0.333 upper 30.6 
#>  6 00:00            Zch_Stampf… NOx       h1       ppb    1826 0.333 ymax  68.3 
#>  7 00:00            Zch_Stampf… O3        h1       µg/m3  1826 0.333 midd… 38.0 
#>  8 00:00            Zch_Stampf… O3        h1       µg/m3  1826 0.333 midd… 38.6 
#>  9 00:00            Zch_Stampf… O3        h1       µg/m3  1826 0.333 ymin   1.29
#> 10 00:00            Zch_Stampf… O3        h1       µg/m3  1826 0.333 lower 12.5 
#> # ℹ 422 more rows