[R] Gaps in time series.

Gabor Grothendieck ggrothendieck at gmail.com
Sun Aug 3 15:02:24 CEST 2008


If you are using zoo for this you can do:

library(zoo)

set.seed(1)
x <- zoo(rnorm(7), as.numeric(1:7))
y <- zoo(rnorm(4), c(1, 2, 6, 7))

xy <- merge(x,y)
xy$y - xy$x

# or if you just want the difference at times existing in both
y - x

On Sat, Aug 2, 2008 at 5:16 PM,  <rkevinburton at charter.net> wrote:
> I like the fact that in subtracting two time series objects that there is some effort to align the series. So if I have a time series of that begins at 1 and one that begins at 2 a subtraction operation makes sure that the proper values are subtracted. But I am unclear as to the best way to build a time series with "holes". say that I have data for "day" 1,2,6,7 in one time series and 1,2,3,4,5,6,7 in another. How do I construct the time series and indicate the missing data for 3,4,5 as in the first series? Eventually I would like to find the difference between the two series. If the difference is series 2 minues series one, then for the indexes of 3,4,5 in the resultant difference  it would just be the series 2 value. The resultant series would have a length of 7.
>
> Thank you.
>
> Kevin
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list