How are your time samples missing? If they are recorded as NA, the na.locf() function will fill them with the previous value (zero-order hold) and with the reversability arguments can give linear interpolation:
library(xts) x = c(1:5,NA,6:10) x = xts(x,Sys.Date()+0:10) na.locf(x) (na.locf(x) + na.locf(x,fromLast=TRUE))/2 If the row is "missing" and you really want to put in data, the following may work -- though most time series analysis techniques are usually able to deal with irregularly spaced data, at least in my work -- library(xts) x = c(1:10) x = xts(x,c(Sys.Date() + 0:4,Sys.Date()+6:10)) tx = seq.Date(from = first(time(x)), to = last(time(x)), by = min(diff(time(x)))) xNew = xts(rep(NA,length(tx)), tx) xNew[time(x)] <- x then fill xNew as before. Hope this helps, Michael Weylandt On Mon, Sep 12, 2011 at 4:42 AM, Eran Eidinger <e...@taykey.com> wrote: > Hello, > > I have a time-series that has some missing samples. > I was thinking on completing them using either zero-order hold or linear > interpolation. > I am looking for an efiicient way (other than a loop...) of identifiying > the > missing time slots and filling them. > > Can you think of any methods that might help here? (obviously > which(diff(time)>min(diff(time))) will give the locations, but what > then....?) > > Thanks, > Eran. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.