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
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.