1

I want to calculate difference between dates. There are characters, for example, '2014-01-01' in days and in groups in R. I did something similar in DB2:

DAYS(DATE(my_date)) - DAYS((LAG(my_date) OVER (PARTITION BY my_group ORDER BY blabla ))

my_group  my_date      diff
1         '2014-01-01'  NA
1         '2014-01-02'  1
1         '2014-01-05'  3
2         '2014-01-01'  NA
2         '2014-01-02'  1
2         '2014-01-06'  4
3         '2014-01-01'  NA
3         '2014-01-02'  1
3         '2014-01-10'  8
3         '2014-01-11'  1
Mario Boss
  • 1,784
  • 3
  • 20
  • 43
Agnieszka
  • 133
  • 10

0 Answers0