Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

na.StructTS

Fill NA or specified positions.


Description

Generic function for filling NA values using seasonal Kalman filter.

Usage

na.StructTS(object, ...)
## S3 method for class 'ts'
na.StructTS(object, ..., na.rm = FALSE, maxgap = Inf)
## S3 method for class 'zoo'
na.StructTS(object, ..., na.rm = FALSE, maxgap = Inf)

Arguments

object

an object.

...

other arguments passed to methods.

na.rm

logical. Whether to remove end portions or fill them with NA.

maxgap

Runs of more than maxgap NAs are retained, other NAs are removed and the last occurrence in the resulting series prior to each time point in xout is used as that time point's output value.

Details

Interpolate with seasonal Kalman filter, using StructTS, followed by tsSmooth. The input object should be a regular time series and have a frequency. It is assumed the cycle length is 1.

See Also

Examples

z <- zooreg(rep(10 * seq(8), each = 4) + rep(c(3, 1, 2, 4), times = 8), 
	start = as.yearqtr(2000), freq = 4)
z[25] <- NA

zout <- na.StructTS(z)

plot(cbind(z, zout), screen = 1, col = 1:2, type = c("l", "p"), pch = 20)

zoo

S3 Infrastructure for Regular and Irregular Time Series (Z's Ordered Observations)

v1.8-10
GPL-2 | GPL-3
Authors
Achim Zeileis [aut, cre] (<https://orcid.org/0000-0003-0918-3766>), Gabor Grothendieck [aut], Jeffrey A. Ryan [aut], Joshua M. Ulrich [ctb], Felix Andrews [ctb]
Initial release
2022-04-15

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.