wmean: Calculates weighted arithmetic means of irregular data series

View source: R/wmean.R

wmeanR Documentation

Calculates weighted arithmetic means of irregular data series

Description

Sometimes records (e.g. measurements from passive samplers or miniDOAS) provide values representative irregular time intervals such as starting from odd start times to odd end times. For example 09:58 to 10:08 or 20 Feb to 06 March. This function interpolates the irregular data on a standard interval. It handles down- and upsampling correct.

Usage

wmean(
  data,
  ...,
  starttime = "starttime",
  endtime = "endtime",
  value = "value",
  interval = "h1"
)

Arguments

data

data.frame for averaging; df has to be in long format and contain a start- and end-time column of class POSIXct (arbitrarily named)

...

columns containing values for grouping (passed to dplyr::group_by()) when calculating weighted means (e.g. for different measurement parameters). Columns not explicitly passed are dropped

starttime

name of starttime column as symbol or string

endtime

name of endtime column as symbol or string

value

name of column containing values to be averaged as symbol or string

interval

specifying the output interval for averaging as string

Value

tibble with the starttime, endtime, value and grouping columns and additional the column "n" containing the sum of weighted intervals within the averaged time interval (data availability in interval, 1 = 100\

Caution

  • Removes NA values to correctly calculate data availability for each interval

  • output data isn't padded

Examples

fn <- system.file("extdata", "Zch_Stampfenbachstrasse_h1_2013_Jan.csv", package = "rOstluft.data")
ps_fn <- system.file("extdata", "NO2_PS.rds", package = "rOstluft.data")
data <- read_airmo_csv(fn, time_shift = lubridate::period(25, "minutes"))
data_ps <- readRDS(ps_fn) %>% pluck_site("Zch_Stampfenbachstrasse")

df <- pluck_parameter(data, "CO") %>%
  pluck_unit("ppm") %>%
  dplyr::mutate(endtime = .data$starttime + lubridate::hours(1)) %>%
  dplyr::select(-interval)

wmean(df, site, parameter, unit, interval = "h1")

wmean(df, site, parameter, unit, interval = "m1")

wmean(df, site, parameter, unit, interval = "y1")

wmean(data_ps, site, parameter, unit, interval = "d1")

wmean(data_ps, site, parameter, unit, interval = "1 week")

wmean(data_ps, site, parameter, unit, interval = "m1")

wmean(data_ps, site, parameter, unit, interval = "y1")


Ostluft/rOstluft documentation built on Feb. 6, 2024, 1:26 a.m.