0

I have daily data that starts from 01-10-2014 to 30-09-2016. I am trying to create a time series using ts. I believe my specifications for ts function is correct but I am still getting wrong Start and End date. I tried both the day of the as the argument to the ts as suggested in different forums :

data=runif(731)
obs_ts_daily <- ts(data,     # random data
         start=c(2014,274),
         frequency =365 )
head(obs_ts_daily)

which returns:

 Time Series:
 Start = c(2014, 274) 
 End = c(2014, 279) 
 Frequency = 365 
 [1] 0.4841401 0.7060281 0.5763160 0.4285645 0.4626230 0.912378

As you can see the Start and End date of the ts object is wrong. I also the decimal date:

obs_ts_daily <- ts(data,     # random data
               start=decimal_date(as.Date("2014-10-01")),
               frequency =365 )

Which returns exactly the same thing as a day of the year case. My question is what should I do to get the right Start and End date for the ts object?

EDIT:I already saw the post [starting a daily time series in R ] and their solution. I do exactly the same, for example:

myts <- ts(rnorm(length(inds)),     # random data
       start = c(2014, as.numeric(format(inds[1], "%j"))),
       frequency = 365)

is exactly what I've done:

data=runif(731)
obs_ts_daily <- ts(data,     # random data
         start=c(2014,274),
         frequency =365 )
head(obs_ts_daily)

Another solution is to use Zoo package for daily data, that is not my interest as I need ts object for another package. Another answer proposes putting frequency=7, but I have daily data and I believe it should be 365 (or 365.25).

Ress
  • 667
  • 1
  • 7
  • 24
  • Please scroll down to [this answer](https://stackoverflow.com/a/33129922/89482) in the link to the duplicate question. It's exactly the same as your issue. – neilfws May 14 '19 at 00:21
  • @neilfws Thanks. I saw this post before, their solution is what exactly I've done. For example: `start = c(2014, as.numeric(format(inds[1], "%j")))` is exactly `Start = c(2014, 274)`. Other solutions such as using Zoo package or setting frequency=7 do not help me. Because I need ts object as an input to other packages. – Ress May 14 '19 at 15:10

0 Answers0