0

I have a data.table with orders. And I want to calculate intervals between orders for each customer. So, dataset looks like:

N   order_id  user_id  order_date
1:  1         1        2016-11-18
2:  2         2        2016-11-20
3:  3         3        2016-11-21
4:  4         1        2016-11-22
5:  5         2        2016-11-23

What I need is to find a column previous_order_date which will show the date of a previous order for current customer. So my data.table will look like this:

N   order_id  user_id  order_date  previous_order_date
1:  1         1        2016-11-18  NA
2:  2         2        2016-11-20  NA
3:  3         3        2016-11-21  NA
4:  4         1        2016-11-22  2016-11-18
5:  5         2        2016-11-23  2016-11-20

Any suggestions? Thanks a lot!

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
matvey.co
  • 381
  • 1
  • 4
  • 9

0 Answers0