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.

Step 2 creates the filtering weights. We used a window of seven periods. This means that the weighted average of the current value and six others will comprise the filtered value at the current position.

Step 3 computes the two-sided filter (the weighted average of the current value and three prior and three succeeding values) and a one-sided filter based on the current value and six prior ones.

Step 4 plots the original data and the symmetric and one-sided filters. We can see that the two-sided filter tracks the changes earlier.

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