Мы можем использовать data.table
методы
library(data.table)
setDT(df)[, date_count := frank(as.IDate(date, format = "%m/%d/%Y"),
ties.method = 'dense'), id][]
# id date date_count
# 1: 1 12/31/2019 2
# 2: 1 12/30/2019 1
# 3: 2 12/26/2019 3
# 4: 2 12/25/2019 2
# 5: 2 12/24/2019 1
# 6: 3 12/22/2019 4
# 7: 3 12/21/2019 3
# 8: 3 12/20/2019 2
# 9: 3 12/19/2019 1
#10: 4 12/15/2019 3
#11: 4 12/14/2019 2
#12: 4 12/13/2019 1
данные
df <- structure(list(id = c(1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L,
4L, 4L), date = c("12/31/2019", "12/30/2019", "12/26/2019", "12/25/2019",
"12/24/2019", "12/22/2019", "12/21/2019", "12/20/2019", "12/19/2019",
"12/15/2019", "12/14/2019", "12/13/2019")),
class = "data.frame", row.names = c(NA,
-12L))