Time series analysis using R, how to deal with daily data

I am trying to convert a daily dataset to ts , but how do you deal with a leap year? therefore, what value should be set for a frequency equal to?

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

+4
source share
2 answers

I would suggest using zoo or xts packages (which relies on zoo ). Using these time formats, you can define time series with or without daylight saving time or a leap year.

In addition, I would suggest using the lubridate package to do time calculations. lubridate makes the difference between periods and duration.

The duration class measures the exact time interval between two points in time that you would measure on a stopwatch.

In contrast to the period , for example, "month". But how long does a month last? Depends on which month you have in mind. And, for example, in leap years, the month of February has a different duration, but the same length of the period.

Whether you require a duration or period depends on your subject and purpose. With zoo and lubridate you can choose the one that suits you.

+4
source

To cope with the frequency for a leap year, set the frequency as follows:

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

Source: https://habr.com/ru/post/1501767/


All Articles