hm_agg: Aggregates the table inside a slot to a larger time period

hm_aggR Documentation

Aggregates the table inside a slot to a larger time period

Description

This method allows you to get your data temporally aggregated.

Usage

hm_agg(
  obj,
  slot_name,
  col_name,
  fun,
  period,
  out_name = NULL,
  allow_na = 0,
  start_month = 1,
  end_month = 12,
  relocate = NULL
)

## S4 method for signature 'hydromet_station'
hm_agg(
  obj,
  slot_name,
  col_name,
  fun,
  period,
  out_name = NULL,
  allow_na = 0,
  start_month = 1,
  end_month = 12,
  relocate = NULL
)

## S4 method for signature 'hydromet_compact'
hm_agg(
  obj,
  slot_name,
  col_name,
  fun,
  period,
  out_name = NULL,
  allow_na = 0,
  start_month = 1,
  end_month = 12
)

Arguments

obj

a valid hydromet_XXX class object.

slot_name

string with the name of the slot to aggregate.

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 1: the climatic option returns the all series annual statistics (fun). NOTE 2: when using annually as period, the method will return the starting dates in the first slot column.

out_name

string with the output column(s) name(s). Default values coerce the original name plus the fun argument (e.g.: tair_max).

allow_na

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

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.: ..., start_month = 6, end_month = 5, ...)

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.: ..., start_month = 6, end_month = 5, ...)

relocate

optional. String with the name of the slot where to allocate the aggregated table. It only make sense for hydromet_station class. When using it you must keep in mind that all aggregated series are allocated in a single slot.

Value

A data frame with the Date and the aggregated variable(s) inside the specified slot.

Functions

  • hm_agg(hydromet_station): temporal aggregation method for station class

  • hm_agg(hydromet_compact): temporal aggregation method for compact class

Examples

## Not run: 
# cuevas station
path <- system.file('extdata', package = 'hydrotoolbox')

# use the build method
hm_cuevas <-
  hm_create() %>%
  hm_build(bureau = 'ianigla', path = path,
           file_name = 'ianigla_cuevas.csv',
           slot_name = c('tair', 'rh', 'patm',
                         'precip', 'wspd', 'wdir',
                         'kin', 'hsnow', 'tsoil'),
           by = 'hour',
           out_name = c('tair(°C)', 'rh(%)', 'patm(mbar)',
                        'p(mm)', 'wspd(km/hr)', 'wdir(°)',
                        'kin(kW/m2)', 'hsnow(cm)', 'tsoil(°C)' )
          )

# aggregate air temperature data to mean value
hm_agg(obj = hm_cuevas, slot_name = 'tair', col_name = 'tair(°C)',
      fun = 'mean', period = 'daily', out_name = 't_mean') %>%
 hm_show(slot_name = 'tair')

# the previous command overwrites the original slot, so now we are going
# to relocate the agg values
hm_agg(obj = hm_cuevas, slot_name = 'tair',
      col_name = 'tair(°C)',
      fun = 'mean',
      period = 'daily',
      relocate = 'tmean',
      out_name = 'tmean(°C)',
      ) %>%
 hm_show(slot_name = 'tmean')

## End(Not run)



hydrotoolbox documentation built on April 14, 2023, 12:34 a.m.