Time Series and Forecasting R has extensive facilities for
analyzing time series data. This section describes the creation
of a time series, seasonal decompostion, modeling with
exponential and ARIMA models, and forecasting with the forecast
pacakge. Creating a time series The ts() function will convert a
numeric vector into an R time series object. The format is
ts(vector, start=, end=, frequency=) where start and end are the
times of the first and last observation and frequency is the
number of observations per unit time (1=annual, 4=quartly,
12=monthly, etc.). # save a numeric vector containing 48 monthly
observations # from Jan 2009 to Dec 2012 as a time series object
myts <- ts(myvector, start=c(2009, 1), end=c(2012, 12),
frequency=12) # subset the time series (June 2012 to December
2012) myts2 <- window(myts, start=c(2012, 6), end=c(2012, 12)) #
plot series A time series with additive trend, seasonal, and
irregular components can be decomposed using the stl() function.
Note that a series with multiplica