[R] Imputing missing values in time series

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Mon Jun 25 17:34:12 CEST 2007


On Fri, 22 Jun 2007, Horace Tso wrote:

> Thanks to Mark and Erik for different versions of locf, also Erik's
> pointer to archive where I found another function due to Simon Fear. I
> haven't tested the zoo locf function.

Just as an addition to what Marc already wrote:

"zoo" offers at least two advantages here:
  - it does not break if the first element is NA
  - if available it incorporates the corresponding time stamps

When we wrote na.locf(), Gabor also tried to optimize it for speed. I
haven't compared it to the solutions suggested here but would be surprised
if any of them would substantially faster.

As for your time series, I would recommend that you hold it as a "zoo"
series with "Date" time stamps. See
  vignette("zoo-quickref", package = "zoo")
  vignette("zoo", package = "zoo")
for some examples of "zoo" series in general and na.locf() in particular.
Z



More information about the R-help mailing list