Add rolling n-day average column(s) to daily flows
Adds selected n-day rolling means to a daily streamflow data set. Based on selected n-days and alignment, the rolling
mean for a given day is obtained by averaging the adjacent dates of daily mean values. For example, rolling days of '7'
and 'right'
alignment would obtain a mean of the given and previous 6 days of daily mean flow.
add_rolling_means( data, dates = Date, values = Value, groups = STATION_NUMBER, station_number, roll_days = c(3, 7, 30), roll_align = "right" )
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 |
values |
Name of column in |
groups |
Name of column in |
station_number |
Character string vector of seven digit Water Survey of Canada station numbers (e.g. |
roll_days |
Numeric values of the number of days to apply a rolling mean. Default |
roll_align |
Character string identifying the direction of the rolling mean from the specified date, either by the first
( |
A data frame of the source data with an additional column(s):
QnDay |
rolling means of the n-day flow values of the designated date and adjacent dates, direction of mean specified by roll_align |
Default additional columns:
Q3Day |
rolling means of the 3-day flow values of the designated date and previous 2 days (roll_align = "right") |
Q7Day |
rolling means of the 7-day flow values of the designated date and previous 6 days (roll_align = "right") |
Q30Day |
rolling means of the 30-day flow values of the designated date and previous 29 days (roll_align = "right") |
# Run if HYDAT database has been downloaded (using tidyhydat::download_hydat()) if (file.exists(tidyhydat::hy_downloaded_db())) { # Add default 3, 7, and 30-day rolling mean columns, with "right" alignment add_rolling_means(station_number = "08NM116") # Add custom 5 and 10-day rolling mean columns add_rolling_means(station_number = "08NM116", roll_days = c(5,10)) # Add default 3, 7, and 30-day rolling mean columns, with "left" alignment add_rolling_means(station_number = "08NM116", roll_align = "left") }
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.