dinesh khemani
dinesh khemani

Reputation: 23

Reading Time series data in R

I am trying to import time series data in R with the below code. The data is from 1-7-2014 to 30-4-2017 making it 1035 data point. But when I use the below code it gives 1093 observation.

series <- ts(data1, start=c(2014,7,1), end=c(2017,4,30), frequency = 365)

Can someone help me in understanding where am I going wrong?

Upvotes: 0

Views: 184

Answers (1)

m0nhawk
m0nhawk

Reputation: 24238

ts doesn't allow input for start and end in this form. Either a single number or a vector of two integers is allowed. In second case it's year and day number, starting from 1st January.

With the help of lubridate you can use the following. decimal_date will convert the date to proper integer, suitable for ts.

library(lubridate)    
series <- ts(data1, start=decimal_date(as.Date("2014-07-01")), end=decimal_date(as.Date("2017-04-30") + 1), frequency = 365)

    > length(series)
    [1] 1035

Upvotes: 2

Related Questions