aggDataframe: Aggregates a data frame to a shorter time period

View source: R/aggDataframe.R

aggDataframeR Documentation

Aggregates a data frame to a shorter time period

Description

CRHM data (observations and outputs) are generally produced at hourly time steps. This function aggregates CRHM data to daily, monthly or yearly values. The data can be aggregated by their maxima, minima, means, sums and any combination of these statistics.

Usage

aggDataframe(
  CRHMdataframe,
  columns = 1,
  period = "annual",
  funs = c("mean"),
  AggFilename = "",
  startMonth = 10,
  useSecondYear = TRUE,
  omitMissing = FALSE,
  logfile = ""
)

Arguments

CRHMdataframe

Required. A valid CRHMr data frame.

columns

The columns to be aggregated, not including the datetime. The default is the first column. This can be a vector, i.e. c(1,2,3).

period

The period of aggregation. Must be one of hourly, daily, monthly, yearly (or annual) or hydro. Default is yearly. Multiple-hour aggregation is not yet supported.

funs

A character vector containing the function(s) for aggregation. The default is mean, but can also include min, max, sum, length, delta, and first. The function(s) will be applied to all of the specified columns

AggFilename

Optional. File name for the aggregated data.

startMonth

Optional. Starting month, to be used when aggregating by hydrological year.

useSecondYear

Optional. Logical. Should the hydrological year be based on the first or second calendar year. In other words would January 1, 2015 be the hydrological year 2014 or 2015? The default is TRUE (i.e., the hydrological year would be 2015). Note that the Campbell Scientific program SPLIT uses the first calendar year (i.e., the hydrological year would be 2014). To emulate this program, set useSecondYear to be FALSE.

omitMissing

Optional. If FALSE missing (i.e. NA_real_) values will be included in the aggregation, causing the aggregated values to also be NA_real_, If TRUE, then the missing values will be omitted from the calculations. This option is only used by the functions max, min, mean and sum.

logfile

Optional. Name of the file to be used for logging the action. Normally not used.

Value

Returns a data frame with the aggregated values.

Note

The period of aggregation must be greater than the time step of the CRHM data. This function does NOT remove NA values before differencing.

Author(s)

Kevin Shook

See Also

interpolate impute yearlyPeaks hydroYear

Examples

Badlake.t.monthly <- aggDataframe(BadLake7376,
  period = "monthly",
  columns = 1, funs = c("mean")
)
Badlake.radiation.daily <- aggDataframe(BadLake7376,
  period = "daily",
  columns = c(6, 7, 8), funs = c("mean")
)

CentreForHydrology/CRHMr documentation built on April 6, 2024, 5:27 p.m.