na.locf

0th

Percentile

Last Observation Carried Forward

Generic function for replacing each NA with the most recent non-NA prior to it.

Keywords
ts
Usage
na.locf(object, na.rm = TRUE, ...)
## S3 method for class 'default':
na.locf(object, na.rm = TRUE, rev = FALSE, \dots)
Arguments
object
an object.
na.rm
logical. Should leading NAs be removed?
rev
logical. Should the observations be reversed before applying LOCF? This corresponds to NOCB (next observation carried backward).
...
further arguments passed to methods.
Value

  • An object in which each NA in the input object is replaced by the most recent non-NA prior to it. If there are no earlier non-NAs then the NA is omitted (if na.rm = TRUE) or it is not replaced (if na.rm = FALSE).

See Also

zoo

Aliases
  • na.locf
  • na.locf.data.frame
  • na.locf.list
  • na.locf.default
Examples
az <- zoo(1:6)

bz <- zoo(c(2,NA,1,4,5,2))
na.locf(bz)
na.locf(bz, rev = TRUE)

cz <- zoo(c(NA,9,3,2,3,2))
na.locf(cz)
Documentation reproduced from package zoo, version 1.1-1, License: GPL

Community examples

Looks like there are no examples yet.