简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM