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

na.locf.xts

Last Observation Carried Forward


Description

xts method replace ‘NA’ with most recent non-‘NA’

Usage

## S3 method for class 'xts'
na.locf(object, na.rm = FALSE, fromLast = FALSE, maxgap=Inf, ...)

Arguments

object

an xts object

na.rm

logical. Should leading/trailing ‘NA’'s be removed? The default for xts FALSE is different than the default S3 method in the zoo package.

fromLast

logical. Cause observations to be carried backward rather than forward. Default is FALSE.

maxgap

runs of more than ‘maxgap’ will retain ‘NA’s after the maximum gap specified. See na.locf in the zoo package.

...

unused

Details

This is the xts method for the S3 generic na.locf. The primary difference to note is that after the ‘NA’ fill action is carried out, the default it to leave trailing or leading ‘NA’'s in place. This is different than zoo behavior.

Value

See the documentation in zoo.

Author(s)

Jeffrey A. Ryan

References

‘zoo’

Examples

x <- xts(1:10, Sys.Date()+1:10)
x[c(1,2,5,9,10)] <- NA

x
na.locf(x)
na.locf(x, fromLast=TRUE)
na.locf(x, na.rm=TRUE, fromLast=TRUE)

xts

eXtensible Time Series

v0.12.1
GPL (>= 2)
Authors
Jeffrey A. Ryan [aut, cph], Joshua M. Ulrich [cre, aut], Ross Bennett [ctb], Corwin Joy [ctb]
Initial release

We don't support your browser anymore

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