add_seasons: Add a column of seasons

View source: R/add_seasons.R

add_seasonsR Documentation

Add a column of seasons


Adds a column of seasons identifiers to a data frame with a column of dates called 'Date'. The length of seasons, in months, is provided using the seasons_length argument. As seasons are grouped by months the length of the seasons must be divisible into 12 with one of the following season lengths: 1, 2, 3, 4, 6, or 12 months. The start of the first season coincides with the start month of each year; 'Jan-Jun' for 6-month seasons starting with calendar years or 'Dec-Feb' for 3-month seasons starting with water year starting in December.


  dates = Date,
  water_year_start = 1,



Data frame of daily data that contains columns of dates, flow values, and (optional) groups (e.g. station numbers). Leave blank or set to NULL if using station_number argument.


Name of column in data that contains dates formatted YYYY-MM-DD. Only required if dates column name is not 'Date' (default). Leave blank or set to NULL if using station_number argument.


Character string vector of seven digit Water Survey of Canada station numbers (e.g. "08NM116") of which to extract daily streamflow data from a HYDAT database. Requires tidyhydat package and a HYDAT database. Leave blank if using data argument.


Numeric value indicating the month (1 through 12) of the start of water year for analysis. Default 1.


Numeric value indicating the desired length of seasons in months, divisible into 12. Required.


A tibble data frame of the source data with additional column:


season identifier labelled by the start and end month of the season


# Run if HYDAT database has been downloaded (using tidyhydat::download_hydat())
if (file.exists(tidyhydat::hy_downloaded_db())) {

# Add a column with four annual seasons starting in January
add_seasons(station_number = "08NM116",
            seasons_length = 4)

# Add a column with two annual seasons (of 6 months length) starting in October
add_seasons(station_number = "08NM116", 
            water_year_start = 10,
            seasons_length = 6)

fasstr documentation built on May 29, 2024, 1:24 a.m.