0

Can anyone please tell me how to give the start and end as dates in time-series in R. I know how to give a sequence, say:

ts <- ts(temp, start=1, end=10)

But I want to show starting at Jan 01 and ending in Jan 10 instead of just 1 to 10. Thanks in advance.

ToNoY
  • 1,358
  • 2
  • 22
  • 43
  • 1
    the following line will generate a sequence of dates: seq(as.Date("1910/1/1"), as.Date("1910/1/10"), "days") Maybe that can help. I am not sure. Maybe include a reproducible example showing what you want. – Mark Miller Mar 15 '13 at 19:17
  • Maybe this question will help also: http://stackoverflow.com/questions/4843969/plotting-time-series-with-date-labels-on-x-axis – Mark Miller Mar 15 '13 at 19:25
  • @Mark, I tried the seq, but it doesn't work inside ts command. – ToNoY Mar 15 '13 at 20:23
  • Without a small reproducible example it is difficult to offer much advice. Perhaps you can use julian dates and then convert them to calendar dates for plotting. http://rss.acs.unt.edu/Rdoc/library/CTFS/html/tojulian.html – Mark Miller Mar 15 '13 at 23:11

1 Answers1

1

The basic time-series functionality in ts is probably not going to be enough for you. There are a lot of available tools for working with time-series in R, but the ts class is geared towards representing

"regularly spaced time series (using numeric time stamps). Hence, it is particularly well-suited for annual, monthly, quarterly data, etc"

If you describe your data correctly, the print command will format it nicely. If you wanted your data divided into months, you could do something like this (note the frequency of 12):

> print(ts(round(rnorm(44)), start = c(2012,3), frequency = 12), calendar = TRUE)
     Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2012           2   1  -2  -1   1   1   0  -1   1  -1
2013   1   0   2   1  -1   1  -1  -1   0   2   1   2
2014   2   0  -1   0   1   1   0   0   2  -1   0   0
2015   2   0   0  -1   0   0   0   1   2   0        

Since you want daily intervals, you're going to want to set frequency to 365:

> print(ts(letters, start = c(2013, 1), frequency = 365), calendar = TRUE)
     p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16 p17 p18 p19 p20 p21
2013  a  b  c  d  e  f  g  h  i   j   k   l   m   n   o   p   q   r   s   t   u
     p22 p23 p24 p25 p26
2013   v   w   x   y   z

Which is going to look rather awkward, but will solve your problem in that it won't just give you a number for each day. However, as stated in the docs, the ts class only supports "numeric time stamps" so this is probably the best you're going to get with built in ts features.

If you want more advanced features I would have a look at some of the tools in this documentation.

Wilduck
  • 13,822
  • 10
  • 58
  • 90
  • actually i know how to use c(2013, 1) which essentially means starting from Jan 1. But is there any other way to include the day there?? it doesn't even work like: start = 1910/1/1, end= 1910/1/10?? – ToNoY Mar 15 '13 at 20:27
  • @ToNoY Not really, no. Why do you want it to work like that? The purpose of using `ts` is less about displaying the data, and more about enforcing regularity of intervals for some more abstract calculations. If you just want dates, just use dates. – Wilduck Mar 15 '13 at 20:32