Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

na.fill

Fill NA or specified positions.


Description

Generic function for filling NA values or specified positions.

Usage

na.fill(object, fill, ...)
## S3 method for class 'ts'
na.fill(object, fill, ix, ...)
## S3 method for class 'zoo'
na.fill(object, fill, ix, ...)
## Default S3 method:
na.fill(object, fill, ix, ...)

na.fill0(object, fill, ix = !is.na(object))

Arguments

object

an object.

fill

a three component list or a vector that is coerced to a list. Shorter objects are recycled. The three components represent the fill value to the left of the data, within the interior of the data and to the right of the data, respectively. The value of any component may be the keyword "extend" to indicate repetition of the leftmost or rightmost non-NA value or linear interpolation in the interior. NULL means that items are dropped rather than filled.

ix

logical. Should be the same length as the number of time points. Indicates which time points not to fill. This defaults to the non-NA values.

...

further arguments passed to methods.

Details

na.fill is a generic function for filling NA or indicated values. It currently has methods for the time series classes "zoo" and "ts" and a default method based on the "zoo" method.

Furthermore, na.fill0 works with plain vectors and "Date" objects. It also works with "zoo" objects provided that no fill component is NULL.

See Also

Examples

z <- zoo(c(NA, 2, NA, 1, 4, 5, 2, NA))
na.fill(z, "extend")
na.fill(z, c("extend", NA))
na.fill(z, -(1:3))
na.fill(z, list(NA, NULL, NA))

zoo

S3 Infrastructure for Regular and Irregular Time Series (Z's Ordered Observations)

v1.8-10
GPL-2 | GPL-3
Authors
Achim Zeileis [aut, cre] (<https://orcid.org/0000-0003-0918-3766>), Gabor Grothendieck [aut], Jeffrey A. Ryan [aut], Joshua M. Ulrich [ctb], Felix Andrews [ctb]
Initial release
2022-04-15

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.