data_agg | R Documentation |
Temporal aggregation of data with different possible aggregation functions.#'
data_agg(data, dates, agg = NULL, aggFun = "mean", input.mch = FALSE)
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 |
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.
A list with aggregated data and dates.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.