Learn R Programming

grwat (version 0.0.4)

gr_fill_gaps: Fill missing daily data

Description

Use the function to fill the missing daily data by linear interpolation. These can be both missing dates and missing runoff or temperature values. A preliminary summary of missing data can be viewed by gr_get_gaps()

Usage

gr_fill_gaps(hdata, autocorr = 0.7, nobserv = NULL)

Value

data.frame which is a filled version of hdata

Arguments

hdata

data.frame with at least two columns, where the first column is Date, and the remaining columns have numeric type.

autocorr

Autocorrelation value that defines possible length of the period that can be filled. Defaults to 0.7. If nobserv parameter is set, then this parameter is ignored. If both parameters are NULL, then all gaps are filled disregard of their lengths (not recommended).

nobserv

Maximum number of contiguous observations that can be interpolated. Defaults to NULL. If this parameter is set, then autocorr parameter is ignored. If both parameters are NULL, then all gaps are filled disregard of their lengths (not recommended).

Examples

Run this code
library(grwat)
library(dplyr)

# example Spas-Zagorye data is included with grwat package
path = system.file("extdata", "spas-zagorye.txt", 
                   package = "grwat")

hdata_raw = read.delim(path, header = FALSE, 
                       sep = ' ', na.strings = c('-999', '-999.0', '-'),
                       col.names = c('d', 'm', 'y', 'q'))

hdata = hdata_raw %>% 
  transmute(Date = lubridate::make_date(y, m, d), 
            Q = q)

head(hdata)

# identify gaps
gr_get_gaps(hdata) 

# fill gaps
fhdata = gr_fill_gaps(hdata, autocorr = 0.8)

# check the results
gr_get_gaps(fhdata)

# fill gaps
fhdata = gr_fill_gaps(hdata, nobserv = 7)

# check the results
gr_get_gaps(fhdata)

Run the code above in your browser using DataLab