na.stinterp | R Documentation |
Generic functions for replacing each NA
with Stineman interpolated values.
na.stinterp(object, ...)
## Default S3 method:
na.stinterp(object, along = time(object), na.rm = TRUE, ...)
object |
object in which |
along |
variable to use for interpolation. Has to be numeric, is otherwise coerced to numeric. |
na.rm |
logical. Should leading and trailing |
... |
further arguments passed to methods. |
Missing values (NA
s) are replaced by piecewice rational
interpolation via stinterp
.
By default the time index associated with object
is used
for interpolation. Note, that if this calls time.default
this gives an equidistant spacing 1:NROW(object)
. If object
is a matrix or data.frame, the interpolation is done separately for
each column.
An object in which each NA
in the input object is replaced
by interpolating the non-NA
values before and after it.
Leading and trailing NA
s are omitted (if na.rm = TRUE
)
or not replaced (if na.rm = FALSE
).
Gabor Grothendieck
stinterp
.
na.stinterp(c(2,NA,1,4,5,2))
na.stinterp(ts(c(2,NA,1,4,5,2)))
## Not run:
#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")))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.