Session Ready
Exercise

Bucketed lags with by

Note that you can even construct lags with a by clause, so they'll "just work" even when your data is in long format.

A data.table called experimentDT is available in the session. It holds the results of an experiment on two subjects measured over 3 days.

Instructions
100 XP
  • Add the column "yesterday", the 1-day lag of "result" for each subject.
  • Add another column called "two_days_ago" that holds the two-day lag of "result".
  • Use print() to view the new state of experimentDT. Notice the stair-step of NAs caused by the lags.