I would like to fill NAs with 0 in an xts with a maxgap of 3.
library(xts)
# make sample xts with gaps
x <- zoo(1:20, Sys.Date() + 1:20)
x[2:4] <- NA # Short run of NA's
x[10:16] <- NA # Long run of NA's
#This is what I want to do, but it does not work
na.fill(x, 0, maxgap=3)
The maxgap argument is ignored and all NAs are filled with 0, I was hoping it would work like na.approx
Clarification to address @RLave 's question, I want to replace every series of NAs of length 3 or less. Series of NAs of length 4 or more should remain unmodified. Desired behavior should be the same as na.approx