[R] is a sequence of dates consecutive, without gaps?

Christopher W. Ryan cryan at binghamton.edu
Wed Jul 22 05:27:37 CEST 2009


Thanks, Phil and Marc; exactly what I needed! I didn't know about the
diff function.

--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]

Marc Schwartz wrote:
> 
> 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