
Last chance! 50% off unlimited learning
Sale ends in
NA
with interpolated
values.na.approx(object, ...)
## S3 method for class 'default':
na.approx(object, along = index(object), na.rm = TRUE, ...)
na.spline(object, ...)
## S3 method for class 'default':
na.spline(object, along = index(object), na.rm = TRUE, ...)
NA
s are to be replacedNA
s be removed?NA
in the input object is replaced
by interpolating the non-NA
values before and after it.
Leading NA
s are omitted (if na.rm = TRUE
) or not replaced (if na.rm = FALSE
).NA
s) are replaced by linear interpolation via
approx
or cubic spline interpolation via spline
,
respectively.
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.zoo
, approx
, spline
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)))
Run the code above in your browser using DataLab