Session Ready
Exercise

Generating and tagging differences

Often in time series analysis, it's valuable to analyze the first differences of the variables of interest. The first difference involves taking each value and subtracting the previous value from it.

In this exercise, you'll implement add_diffs(), a function to generate first differences and add them to a time series dataset!

metalsDT is available in your session.

Instructions 1/2
undefined XP
  • 1
  • 2

Complete add_diffs().

  • One new column per each column in DT indicated by cols.
  • New names follow the convention "<source_column>_diff<ndiff>".
  • New columns contain the ndiff-period difference of each source column.