Skip to content
Prev 176229 / 398503 Next

time-series data and time-invariant missing values

Check out na.locf in the zoo package.  Here we fill in
NAs going forward and just in case there were NAs
right at the beginning we fill them in backward as well.

library(zoo)
x <- as.Date(c(NA, "2000-01-01", NA))
x2 <- na.locf(x, na.rm = FALSE)
x2 <- na.locf(x2, fromLast = TRUE, na.rm = FALSE)

gives:
[1] "2000-01-01" "2000-01-01" "2000-01-01"
On Mon, Apr 6, 2009 at 7:13 AM, Kunzler, Andreas <a.kunzler at bzaek.de> wrote: