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. > > --ChrisChris, 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
Christopher W. Ryan
2009-Jul-21 21:58 UTC
[R] is a sequence of dates consecutive, without gaps?
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 -- Christopher W. Ryan, MD SUNY Upstate Medical University Clinical Campus at Binghamton 40 Arch Street, Johnson City, NY 13790 cryanatbinghamtondotedu "If you want to build a ship, don't drum up the men to gather wood, divide the work and give orders. Instead, teach them to yearn for the vast and endless sea." [Antoine de St. Exupery]
Reasonably Related Threads
- automatic exploration of all possible loglinear models?
- stuck on making a line graph across time, with 4 categories
- question about a small "for" loop
- conditional coloring of output text in console or in GUI
- using Sweave with a master file that has several iputted .tex files