agg_table | R Documentation |
Aggregates a data frame to a larger time period
agg_table(
x,
col_name,
fun,
period,
out_name = NULL,
allow_na = 0,
start_month = 1,
end_month = 12
)
x |
data frame or tibble with class |
col_name |
string with column(s) name(s) to aggregate. |
fun |
string with supported aggregation function name (one per col_name): mean, min, max, sum, last or first. |
period |
string with the aggregation time-step: hourly, daily, monthly, annually or climatic. NOTE: the climatic option returns the all series annual statistics (fun). |
out_name |
optional. String with the output column(s) name(s). Default values coerce the original
name plus the fun argument (e.g.: |
allow_na |
optional. Numeric value with the maximum allowed number of |
start_month |
optional. Numeric value defining the first month of the annual
period (it just make sense if period is either annually or
climatic). Default sets to 1 (January). NOTE: keep in mind that if you
choose climatic as period you have to round off a complete year (e.g.:
|
end_month |
optional. Numeric value defining the last month of the annual period
(it just make sense if period is either annually or
climatic). Default sets to 12 (December). NOTE: keep in mind that if
you choose climatic as period you have to round off a complete year (e.g.:
|
A data frame with the Date and the aggregated variable(s).
# set path to file
path <- system.file('extdata', 'snih_qd_guido.xlsx',
package = 'hydrotoolbox')
# read and load daily streamflow with default column name
guido_qd <- read_snih(path = path, by = 'day', out_name = 'q(m3/s)')
# aggregate daily to monthly discharge
guido_q_month <- agg_table(x = guido_qd, col_name = 'q(m3/s)',
fun = 'mean', period = 'monthly',
out_name = 'qm(m3/s)')
# suppose that we are interested on getting the annual maximum
# daily mean discharge for every hydrological year (since this
# station is located at the Mendoza River Basin ~32.9º S, we will
# consider that annual period starts on July)
guido_q_annual <- agg_table(x = guido_qd, col_name = 'q(m3/s)',
fun = 'max', period = 'annually',
out_name = 'qmax(m3/s)',
start_month = 7, end_month = 6)
# now we want the mean, maximum and minimum monthly discharges
guido_q_stats <- agg_table(x = guido_qd, col_name = rep('q(m3/s)', 3),
fun = c('mean', 'max', 'min'),
period = 'monthly')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.