CAT | Time Series
There are many time series packages in R, so someone coming from a commercial application (e.g. Matlab or S-Plus) can experience a learning curve (and some amount of frustration) trying to learn the best toolkit.
R comes with one object called ts() which is useful for regularly spaced time series, such as daily, monthly, or yearly data (see help(ts) for more details). See "Time Series Analysis with R" for an example of how to work with this.
This is frequently insufficient for our purposes. As such, I will primarily use the zoo and xts packages on this blog. The other options are timeSeries (which is part of Rmetrics), its, or fts (from Whit Armstrong). I will touch on some of the differences along the way. You can find more about the time series package on the CRAN view.
zoo was created originally by Achim Zeileis in 2005, and it stands for "Zeileis's ordered observations", with many subsequent contributions from Gabor Grothendieck. One of the nice things about zoo is that it is an S3 class in R, and it works with most of the standard R matrix functions (such as summary, cbind, merge, and aggregate). Hence it has a relatively small learning curve and the authors put a lot of thought into making it just work as expected.
Here's a quick example creating a dummy multivariate time series, getting a summary of the output, and plotting it:
> x1 <- zoo(matrix(rnorm(12), nrow = 6), as.Date("2008-08-01") + 0:10)
> colnames (x1) <- c ("A", "B")
> summary(x1)
Index A B
Min. :2008-08-01 Min. :-1.6231 Min. :-1.3363
1st Qu.:2008-08-03 1st Qu.:-0.9867 1st Qu.:-0.7071
Median :2008-08-06 Median :-0.5078 Median :-0.5753
Mean :2008-08-06 Mean :-0.1310 Mean :-0.1270
3rd Qu.:2008-08-08 3rd Qu.: 0.6633 3rd Qu.: 0.6533
Max. :2008-08-11 Max. : 1.8866 Max. : 1.0704
> plot(x1)
Read the zoo vignette for more details.
fts · its · R · Time Series · timeSeries · ts · xts · zoo
