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.
add_seasons( data, dates = Date, station_number, water_year_start = 1, seasons_length )
data |
Data frame of daily data that contains columns of dates, flow values, and (optional) groups (e.g. station numbers).
Leave blank if using |
dates |
Name of column in |
station_number |
Character string vector of seven digit Water Survey of Canada station numbers (e.g. |
water_year_start |
Numeric value indicating the month ( |
seasons_length |
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 |
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) }
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.