na.stinterp(c(2,NA,1,4,5,2))
na.stinterp(ts(c(2,NA,1,4,5,2)))
if (FALSE) {
#comparison of gap filling with na.stinterp/stinterp and splines,
#the solid lines show the continuous interpolation functions
#implicitly assumed by the gap-filling, they show how the Stineman
#interpolation restricts the range of the interpolant to the
#nearby range of the points and suppresses the well known oscillations
#characteristic of splines and other methods based on polynomials
x <- 1:6
y <- c(2,NA,1,4,5,2)
plot(x,y,ylim=c(-1,5))
points(na.stinterp(c(2,NA,1,4,5,2)),pch=2,col=2)
points(spline(x,y,n=6),pch=3,col=3)
lines(stinterp(x[!is.na(y)],y[!is.na(y)],xout=seq(1,6,by=0.1)),col=2)
lines(spline(x,y,n=50),col=3)
library(zoo)
na.stinterp(zoo(c(2,NA,1,4,5,2)))
library(its)
na.stinterp(its(c(2,NA,1,4,5,2), seq(Sys.time(), length = 6, by = "day")))
}
Run the code above in your browser using DataLab