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

Step 1 reads the data, and Step 2 creates and plots the time series. For more details, refer to the Using time series objects recipe earlier in this chapter.

Step 3 shows the use of the stl function to decompose an additive time series. Since our earlier plot indicated that the amplitude of the fluctuations increased with time, thereby suggesting a multiplicative time series, we applied the log function to convert it into an additive time series and then decomposed it.

Step 4 uses the plot function to plot the results.

Step 5 uses the decompose function to perform a decomposition through moving averages and then plots it.

Step 6 adjusts gas prices for seasonality by subtracting the seasonal component from the original time ...

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