data_agg: Temporal aggregation of daily or hourly data.

View source: R/data_agg.R

data_aggR Documentation

Temporal aggregation of daily or hourly data.

Description

Temporal aggregation of data with different possible aggregation functions.#'

Usage

data_agg(data, dates, agg = NULL, aggFun = "mean", input.mch = FALSE)

Arguments

data

Matrix with the data to be aggregated (time steps in rows, stations in columns).

dates

Vector of dates (POSIX class) of the original data.

agg

Level of temporal aggregation: daily ("D", only for hourly input data), monthly ("M"), seasonal ("S"), annual ("Y").

aggFun

Function for temporal aggregation. Possible values: mean, median, min, max. Default: mean.

input.mch

logical. If the input data is from DWH, the hourly needs to be aggregated differently. Default: FALSE

Details

The result is a multi-year series. The input series is first filled with NA to have full years, i.e. the result will have NAs for the season/month with no data at all. If a season/month has data but is not complete, a warning is shown.

Value

A list with aggregated data and dates.

Examples

## Not run: 
# Generate some data
dates.day <- seq(as.POSIXct(as.Date("20160101", format='%Y%m%d'), tz="UTC"), 
as.POSIXct(as.Date("20171231", format='%Y%m%d'), tz="UTC"), by="day") 
dates.hour <-seq(as.POSIXlt("201601010000", format='%Y%m%d%H%M'), 
as.POSIXlt("201712312350", format='%Y%m%d%H%M'), by="hour") 
data.day <- array(runif(length(dates.day)*2, -5, 30), dim=c(length(dates.day),2)) 
data.hour <- rnorm(length(dates.hour), mean=15, sd=2)
# Aggregate from daily to annual
data_agg(data.day, dates.day, agg="Y", aggFun="mean") 
# Aggregate from daily to monthly
data_agg(data.day, dates.day, agg="M", aggFun="max") 
# Aggregate from daily to seasonal
data_agg(data.day, dates.day, agg="S", aggFun="min") 
# Aggregate from hourly to daily
data_agg(data.hour, dates.hour, agg="D", aggFun="mean") 

## End(Not run)

anacv/plotFun documentation built on June 21, 2022, 10:31 p.m.