Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)?

like image 731
George Gao Avatar asked Sep 12 '13 04:09

George Gao


1 Answers

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.

like image 178
nnn Avatar answered Sep 24 '22 13:09

nnn