Add year, month, and day of year variable columns to daily flows
Add columns of CalendarYear (YYYY), Month (MM), MonthName (e.g. 'Jan'), WaterYear (YYYY), and DayofYear (1-365 or 366; of WaterYear); to a data frame with a column of dates called 'Date'. Water years are designated by the year in which they end. For example, Water Year 1999 (starting Oct) is from 1 Oct 1998 (DayofYear 1) to 30 Sep 1999 (DayofYear 365)).
add_date_variables(data, dates = Date, station_number, water_year_start = 1)
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 ( |
A tibble data frame of the source data with additional columns:
CalendarYear |
calendar year |
Month |
numeric month (1 to 12) |
MonthName |
month abbreviation (Jan-Dec) |
WaterYear |
year starting from the selected month start, water_year_start |
DayofYear |
day of the year from the selected month start (1-365 or 366) |
# Run if HYDAT database has been downloaded (using tidyhydat::download_hydat()) if (file.exists(tidyhydat::hy_downloaded_db())) { # Add date variables using calendar years add_date_variables(station_number = "08NM116") # Add date variables using water years starting in August add_date_variables(station_number = "08NM116", water_year_start = 8) }
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.