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 does not allow 'gaps' in its class "ts". Irregular time series are covered in several packages, including tseries, its and zoo. On Sat, 2 Aug 2008, 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. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
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. >