简体   繁体   中英

Time Series analysis with R, how to deal with daily data

I try to convert a daily dataset to ts , but how do you deal with leap year? so what value should I set the frequency equal to?

ts(data,start=c(2010,1,1),frequency=365)?

I would suggest using the packages zoo or xts (which relies on zoo ). With these time formats you can define the time series with or without daylight saving times or leap years.

Additionally I would suggest using the package lubridate to do timespan calculations. lubridate makes a difference between periods and durations.

The duration class measures the exact time span between two moments in time, that you would measure on a stop watch.

In contrast a period is for example "a month". But how long is a month? Depends on which month you mean. And for example in leap years month february has a different duration, but same period length.

Whether you need the duration or the period depends on your subject and objective. With zoo and lubridate you can choose the one that is relevant for you.

To deal with frequency for leap year, set frequency as given below:

date=c(2010,1,1)

ts(data,start=date,frequency=365+1* (!date[1]%%400 || ((date[1]%%100)&&!date[1]%%4) ))?

频率可以设置为 365.25 以包括闰年

ts(data,start=c(2010,1,1),frequency=365.25)

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