Infills missing time values from a time series based on a regular interval.
rvn_ts_infill(ts)
valid xts time series
continuous xts time series
Takes xts dataset, finds minimum interval between time stamps and
returns a new regular interval xts with same data content, but NA
values in between known
data values
Only handles data with minimum time interval of 1 day; 1,2,3,4,6,8, or 12 hrs.
Note that in default reading in of date/time data, the daylight savings timezones may be assigned
to the date/time when reading in a data file with Raven using functions such as rvn_hyd_read
. This
function will then detect differences in the intervals and throw an error. To avoid this, the
timezone may be assigned explicitly to all values with the read function and all daylight savings/endings
will be ignored.
system.file("extdata","run1_Hydrographs.csv", package="RavenR") %>%
rvn_hyd_read(., tzone="EST") -> mydata
mydata <- mydata$hyd$precip
mydata<-mydata[-seq(2,nrow(mydata),3),] # remove every 3rd day
head(mydata)
#> Warning: object timezone ('EST') is different from system timezone ('UTC')
#> NOTE: set 'options(xts_check_TZ = FALSE)' to disable this warning
#> This note is displayed once per session
#> precip
#> 2002-10-01 NA
#> 2002-10-03 1.1891800
#> 2002-10-04 2.0832600
#> 2002-10-06 0.1255910
#> 2002-10-07 0.8412070
#> 2002-10-09 0.0642942
# fill back with rvn_ts_infill using NA values
rvn_ts_infill(mydata$precip) %>%
head()
#> Warning: object timezone ('EST') is different from system timezone ('UTC')
#> precip
#> 2002-10-01 NA
#> 2002-10-02 NA
#> 2002-10-03 1.189180
#> 2002-10-04 2.083260
#> 2002-10-05 NA
#> 2002-10-06 0.125591