How to do it...

The following steps decompose the time series:

  1. Read the data. The file has the Bureau of Labor Statistics monthly price data for unleaded gas and white flour for 1980 through 2014:
> prices <- read.csv("prices.csv") 
  1. Create and plot the time series of gas prices:
prices.ts = ts(prices, start = c(1980,1), frequency = 12) 
> plot(prices.ts) 

The following is the plot of time versus prices as per our command:

  1. The preceding plot shows seasonality in gas prices. The amplitude of fluctuations seems to increase with time, and hence this looks like a multiplicative time series. Thus, we will use the log of the prices to make it ...

Get R Data Analysis Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.