fill_missing_dates {fasstr} | R Documentation |
Fills data gaps of missing dates
Description
Fills data gaps of missing dates of the data provided. Builds a continuous data set from the start date to the end date.
Only missing dates are filled, columns not specified as dates or groups will be filled with NA. Will completely fill first and
last years, unless specified using pad_ends = FALSE
.
Usage
fill_missing_dates(
data,
dates = Date,
values = Value,
groups = STATION_NUMBER,
station_number,
water_year_start = 1,
pad_ends = TRUE
)
Arguments
data |
Data frame of daily data that contains columns of dates, flow values, and (optional) groups (e.g. station numbers).
Leave blank or set to |
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. |
water_year_start |
Numeric value indicating the month ( |
pad_ends |
Logical value indicating whether to fill incomplete start and end years with rows of dates.
If |
Value
A tibble data frame of the source data with additional rows where missing dates existed.
Examples
# Run if HYDAT database has been downloaded (using tidyhydat::download_hydat())
if (file.exists(tidyhydat::hy_downloaded_db())) {
# Fill missing dates with NA using calendar years
fill_missing_dates(station_number = "08NM116")
# Fill missing dates with NA using water years starting in August
fill_missing_dates(station_number = "08NM116",
water_year_start = 8)
}