Fill NA in a time series only to a limited number
问题 Is there a way we can fill NA s in a zoo or xts object with limited number of NA s forward. In other words like fill NA s up to 3 consecutive NA s, and then keep the NA s from the 4th value on until a valid number. Something like this. library(zoo) x <- zoo(1:20, Sys.Date() + 1:20) x[c(2:4, 6:10, 13:18)] <- NA x 2014-09-20 2014-09-21 2014-09-22 2014-09-23 2014-09-24 2014-09-25 2014-09-26 1 NA NA NA 5 NA NA 2014-09-27 2014-09-28 2014-09-29 2014-09-30 2014-10-01 2014-10-02 2014-10-03 NA NA NA