Josh, Great use of rle()! I knew it had to fit in there somewhere! Thanks for the help!
Tim Tim Clark Marine Ecologist National Park of American Samoa Pago Pago, AS 96799 ----- Original Message ---- From: Joshua Wiley <jwiley.ps...@gmail.com> To: Tim Clark <mudiver1...@yahoo.com> Cc: r help r-help <r-help@r-project.org> Sent: Wed, November 10, 2010 7:45:15 PM Subject: Re: [R] Count continuous dates Hi Tim, Thanks for providing nice sample data! It made this super easy :) ## use diff() to find the differences ## use rle() to find the run lengths ## use max to find the highest one max(rle(as.vector(diff(x)))$lengths) Cheers, Josh On Wed, Nov 10, 2010 at 10:07 PM, Tim Clark <mudiver1...@yahoo.com> wrote: > Dear List, > > I have a series of dates and I am needing to know the greatest length of > continuous dates - i.e. the number of dates before a break in the series. For > example, below there are three continuous series of dates with lengths 4, 6, >and > 8. How can I count the number of continuous dates? rle() will do it for > constant integers, but I can't figure a way to modify it for continuous dates. > > x<-c("1/10/10","2/10/10","3/10/10","4/10/10", > "6/10/10","7/10/10","8/10/10","9/10/10","10/10/10","11/10/10", > >"13/10/10","14/10/10","15/10/10","16/10/10","17/10/10","18/10/10","19/10/10","20/10/10") >) > > x<-strptime(x,"%d/%m/%y") > > > > Thanks! > > Tim > Tim Clark > Marine Ecologist > National Park of American Samoa > Pago Pago, AS 96799 > > > > > ______________________________________________ > 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. > -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ ______________________________________________ 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.