agg_serie {hydroToolkit}R Documentation

Aggregates a data frame to a larger time period

Description

This is a useful function to easily aggregate your data.

Usage

agg_serie(
  df,
  fun,
  period,
  out_name,
  start_month = NULL,
  end_month = NULL,
  allow_NA = NULL
)

Arguments

df

data frame with class Date or POSIXct in the first column. The function always aggregates the second column.

fun

string containing one of the following functions: mean, min, max or sum.

period

string with the period of aggregation: hourly, daily, monthly, annual or climatic. NOTE: the 'climatic' option returns the all series annual statistics ('fun').

out_name

string with the output column name of the variable to aggregate.

start_month

optional. Numeric value of the first month. It only makes sense if the period is annual.

end_month

optional. Numeric value of the last month. It only makes sense if the period is annual.

allow_NA

optional. Numeric value with the maximum allowed number of NA_real_ values. By default the function will not tolerate any NA_real_ in an aggregation period (and will return NA_real_ instead).

Value

A data frame with to columns: the date and the aggregated variable.

Examples

# Path to file
dgi_path  <- system.file('extdata', package = "hydroToolkit")

toscas <- read_DGI(file = 'Toscas.xlsx', sheet = 'tmean', path = dgi_path)

# Monthly mean temperature
m_toscas <- agg_serie(df = toscas, fun = 'mean', period = 'monthly', out_name = 'T_month')


[Package hydroToolkit version 0.1.0 Index]