我想计算日期之间的差异(它们是字符,例如' 2014-01-01'天数和R中的组。我在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