O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required