Skip to content
Prev 259918 / 398502 Next

Adding dates to time series

Hi:

I'd suggest using the zoo package; it allows you to use an index
vector such as dates to map to the series. It is well documented and
well maintained, with vignettes and an FAQ that can be found on its
package help page (among other places). Here is a small example:

dd <- data.frame(time = seq(as.Date('1993-01-01'), by = 'months', length = 200),
                     s = rnorm(200))
head(dd, 3)
        time          s
1 2003-01-01  1.4292491
2 2003-02-01 -1.0713998
3 2003-03-01 -0.4738791

library(zoo)
ser <- with(dd, zoo(s, time))   # s is the series, time is the index vector
str(ser)   # ser is of class zoo
plot(ser)      # apply the plot method

For finance applications, other possibilities include the xts and
quantmod packages, both of which are built on zoo.

HTH,
Dennis
On Sun, May 15, 2011 at 11:42 AM, Bazman76 <h_a_patience at hotmail.com> wrote: