na.approx

0th

Percentile

Replace NA by Interpolation

Generic function for replacing each NA with interpolated values.

Keywords
ts
Usage
na.approx(object, ...) 
## S3 method for class 'default':
na.approx(object, along = index(object), na.rm = TRUE, ...)
Arguments
object
object in which NAs are to be replaced
along
variable to use for interpolation. Has to be numeric, is otherwise coerced to numeric.
na.rm
logical. Should leading NAs be removed?
...
further arguments passed to methods.
Details

By default the index associated with object is used for interpolation. Note, that if this calls index.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 NAs are omitted (if na.rm = TRUE) or not replaced (if na.rm = FALSE).

See Also

zoo

Aliases
  • na.approx
  • na.approx.default
Examples
z <- zoo(c(2,NA,1,4,5,2), c(1,3,4,6,7,8))

## use underlying time scale for interpolation
na.approx(z) 
## use equidistant spacing
na.approx(z, 1:6)

na.approx(zoo(c(NA,9,3,2,3,2)))
Documentation reproduced from package zoo, version 1.0-3, License: GPL

Community examples

Looks like there are no examples yet.