Dear Benjamin, timeSequence() ultimately is relying on seq.POSIXt(). If you look at the last paragraph of the "Details" section in ?seq.POSIXt it seems to basically indicate that using by = "month" just sequences through the months and the day is only changed if it is invalid for a particular month (the relevant lines are around 88--100 in the seq.POSIXt code).
It is fairly straightforward ensure the output is less than "to". Here is one option: test <- timeSequence(from = "2008-01-01", to = "2010-12-13", by = "1 month") test <- test[as.Date(test) < as.Date("2010-12-13")] test Cheers, Josh On Thu, Jan 6, 2011 at 1:30 AM, Benjamin B. <benj.bad...@googlemail.com> wrote: > Dear help-list, > > I have a problem with timeSequence {timeDate}. > > When I use it like > >> timeSequence(from = "2008-01-01", to = "2010-12-13", by = "1 month") > GMT > [1] [2008-01-01] [2008-02-01] [2008-03-01] [2008-04-01] [2008-05-01] > [2008-06-01] [2008-07-01] [2008-08-01] [2008-09-01] [2008-10-01] > [2008-11-01] > [12] [2008-12-01] [2009-01-01] [2009-02-01] [2009-03-01] [2009-04-01] > [2009-05-01] [2009-06-01] [2009-07-01] [2009-08-01] [2009-09-01] > [2009-10-01] > [23] [2009-11-01] [2009-12-01] [2010-01-01] [2010-02-01] [2010-03-01] > [2010-04-01] [2010-05-01] [2010-06-01] [2010-07-01] [2010-08-01] > [2010-09-01] > [34] [2010-10-01] [2010-11-01] [2010-12-01] > > The result is as expected: a list of dates with all dates smaller then the > "to" date. > > But somehow it behaves strange when I use it with a different starting date: > >> test <- timeSequence(from = "2008-01-15", to = "2010-12-13", by = "1 > month") > GMT > [1] [2008-01-15] [2008-02-15] [2008-03-15] [2008-04-15] [2008-05-15] > [2008-06-15] [2008-07-15] [2008-08-15] [2008-09-15] [2008-10-15] > [2008-11-15] > [12] [2008-12-15] [2009-01-15] [2009-02-15] [2009-03-15] [2009-04-15] > [2009-05-15] [2009-06-15] [2009-07-15] [2009-08-15] [2009-09-15] > [2009-10-15] > [23] [2009-11-15] [2009-12-15] [2010-01-15] [2010-02-15] [2010-03-15] > [2010-04-15] [2010-05-15] [2010-06-15] [2010-07-15] [2010-08-15] > [2010-09-15] > [34] [2010-10-15] [2010-11-15] [2010-12-15] > > In this case the last calculated date is obviously LARGER than the "to" > date: > >> as.Date(test[length(test)]) < "2010-12-13" > [1] FALSE > > This seem to occur also with other parameters: > >> timeSequence(from = "1999-12-12", to = "2000-06-08", by = "2 months") > GMT > [1] [1999-12-12] [2000-02-12] [2000-04-12] [2000-06-12] > >> timeSequence(from = as.Date("1999-12-12"), to = as.Date("2000-06-08"), by > = "2 months") > GMT > [1] [1999-12-12] [2000-02-12] [2000-04-12] [2000-06-12] > > Am I missing something essential in using timeSequence? > Is this behavior wanted (then I don't get why it should...)? > Is there a better way to get those dates? > > Thanks for reading and greetings, > > Benjamin > > > Benjamin B. > Hamburg, Germany > > ______________________________________________ > 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.