summary_periodic: Summarise a 'rOstluft::format_rolf()' dataset over periodic...

View source: R/summary_periodic.R

summary_periodicR Documentation

Summarise a rOstluft::format_rolf() dataset over periodic (diurnal, weekday, etc) factors implicitly created by cut_timeseries_periodic() using various stat functions.

Description

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

Ostluft/rOstluft.plot documentation built on Jan. 26, 2025, 1:05 a.m.