# na.stinterp

##### Replace NAs by Stineman interpolation

Generic functions for replacing each `NA`

with Stineman interpolated values.

- Keywords
- ts

##### Usage

```
na.stinterp(object, …)
# S3 method for default
na.stinterp(object, along = time(object), na.rm = TRUE, …)
```

##### Arguments

- object
object in which

`NA`

s are to be replaced.- along
variable to use for interpolation. Has to be numeric, is otherwise coerced to numeric.

- na.rm
logical. Should leading and trailing

`NA`

s be removed?- …
further arguments passed to methods.

##### Details

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.

##### Value

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`

).

##### See Also

##### Examples

```
# NOT RUN {
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")))
# }
# NOT RUN {
# }
```

*Documentation reproduced from package stinepack, version 1.3, License: GPL-2*