add_hydro_year: Add a hydrological year column to a data.table (by reference)

View source: R/add_hydro_year.R

add_hydro_yearR Documentation

Add a hydrological year column to a data.table (by reference)

Description

Adds a hydrological year starting at a specific month (default = 10). The hydrological year is identified by the ending month, e.g. 2002-10 to 2002-12 and 2003-01 to 2003-09 will have the same hydro_year=2003.

Usage

add_hydro_year(ref_dat, start_month = 10)

Arguments

ref_dat

a data.table for which to add hydro_year column

start_month

numeric, which should be the first month of the hydro_year

Details

Requires that input data has column(s) "date" or c("year", "month").

Value

Nothing, adds column by reference.

Examples



dat <- data.table::data.table(
  date = lubridate::ymd(c("2002-08-15", "2002-09-30", "2002-10-01", "2002-12-31",
                          "2003-01-01", "2003-08-15", "2003-09-30", "2003-10-01"))
)

dat
add_hydro_year(dat)
dat
add_hydro_year(dat, start_month = 9)
dat

mitmat/mitmatmisc documentation built on Aug. 22, 2024, 3:28 a.m.