Counting frequencies of Continuous Dates

r

Solution

How about this:

Make reproducible example data:

dat <- read.table(text = "2011-08-16
2011-08-17
2011-08-28
2011-09-01
2011-09-05
2011-09-06
2011-10-01
2011-10-02
2011-10-03
2011-10-04")

Get the run count of consecutive dates using `rle`, following this answer and this answer:

(rle (cumsum( c(0, diff(as.Date(dat$V1)) > 1) ) ) )$lengths
[1] 2 1 1 2 4

Problem

I have a data.frame in the form: ``` Date 2011-08-16 2011-08-17 2011-08-28 2011-09-01 2011-09-05 2011-09-06 2011-10-01 2011-10-02 2011-10-03 2011-10-04 ``` What I would like to do is take a run count when Dates occur in order i.e. they are side by side. In the above example, we would have 2,1,1,2,4

Original source

Related problems