ts function in R My time series data are separately by hourly. The length of time series is 1005 days. The start day is 2/04/2014 and the end day is 31/12/2016. I’m using R (3.1.1). I’d like to know the value of the “frequency” argument in the ts() function in R, for annual, seasons and month. Since most of the examples and cases I’ve seen so far are for months or days at the most. Thank you in advance.
 A: Well, a year has $365.25\times 24=8766$ hours, so to look at yearly seasonality for hourly data, you'd enter frequency=8766.
Months are a bit more complicated, since each month has a different number of hours. You could use $8766/12=730.5$.
You will need to be a bit more specific as to what you mean by "seasons", but the above may already answer your question here.
Or are you in fact interested in how to model multiple seasonalities at the same time, e.g., intra-daily and intra-yearly seasonalities? In that case, I'd recommend you look at the msts class in the forecast package.
A: The frequency argument depends on how your data is structured. For instance, you mention that your data is separated on an hourly basis. If you wanted to account for every observation in the time series, then your frequency would be an hourly frequency, i.e. 61320, since that is the number of hours in a year. Therefore, if you are defining by an hourly frequency, your ts() function would be set up as follows:
Hourly
tsfunction <- ts(variable, frequency=61320, start=c(2014,2), end=c(2016,12))
However, if you wanted to structure your data on a daily, monthly, or annual basis as you mentioned (and is a more standard way of doing so), you can accordingly set the function as follows:
Daily
tsfunction <- ts(variable, frequency=24, start=c(2014,2), end=c(2016,12))
The number of intervals per day (as it is measured on an hourly basis) is 24, so R is taking every 24 observations to create a daily time series.
Monthly
tsfunction <- ts(variable, frequency=720, start=c(2014,2), end=c(2016,12))
However, with the number of hours per month being 720 (assuming 30 days per month), then R is selecting the observation for every 720 entries, hence frequency=720.
Annual
There are 8760 hours in a year (365*24), so accordingly frequency is 8760:
tsfunction <- ts(variable, frequency=8760, start=c(2014,2), end=c(2016,12))
As another answer mentioned, please be more specific on what you mean by "seasons".
