[R] is a sequence of dates consecutive, without gaps?
Marc Schwartz
marc_schwartz at me.com
Tue Jul 21 23:23:23 CEST 2009
On Jul 21, 2009, at 4:58 PM, Christopher W. Ryan wrote:
> I have a long sequence of dates, about 6 years worth, as one column
> in a
> data frame. How can I test whether the sequence is consecutive, that
> is,
> without gaps?
>
> Thanks.
>
> --Chris
Chris,
Presuming that your data frame is called DF, the date column is called
'date' AND 'date' has been coerced to a Date class, you could use:
all(diff(DF$date) == 1)
which will tell you if all of the differences between successive dates
in the column are one day.
See ?diff for more information.
If the dates have not yet been coerced to a Date class, see ?as.Date.
HTH,
Marc Schwartz
More information about the R-help
mailing list