R: How to extract dates from a time series

Liza picture Liza · Mar 23, 2015 · Viewed 34.9k times · Source

How can I extract dates from a times series? Here is a time series:

x = seq (1, 768)
myts <- ts(x, start=1982, frequency=24)

Originally I needed to create a vector holding date/time data for the rts function, The observations start 1982 with 2 measurements per month going till 2013.

Answer

G. Grothendieck picture G. Grothendieck · Mar 23, 2015

Try:

time(myts)

or perhaps:

library(zoo)
as.yearmon(time(myts))