[R] Bug in seq.date?

Don MacQueen macq at llnl.gov
Mon Jun 4 18:40:07 CEST 2007


I think you can easily get the last days of the months by creating a 
series starting on the first days, and subtracting one from each.

seq(as.Date("2000-2-1"), as.Date("2001-2-1"), "months") -1

-Don

At 2:01 PM +0200 6/4/07, hadley wickham wrote:
>On 6/4/07, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
>>  Note that chron does give the last day of the month:
>>
>>  > library(chron)
>>  > seq(chron("1/31/2000"), chron("1/31/2001"), "month")
>>   [1] 01/31/00 02/29/00 03/31/00 04/30/00 05/31/00 06/30/00 07/31/00 08/31/00
>>   [9] 09/30/00 10/31/00 11/30/00 12/31/00 01/31/01
>
>Thanks, that's very useful - I'll switch to using chron instead.
>
>Hadley
>
>>  The zoo package has a "yearmon" class whose as.Date.yearmon can
>>  convert a "Date" to the end of the month:
>>  library(zoo)
>>  > library(zoo)
>>  > as.Date(as.yearmon(seq(as.Date("2000-1-31"), 
>>as.Date("2001-1-31"), "month")), 1)
>>   [1] "2000-01-31" "2000-02-29" "2000-03-31" "2000-04-30" "2000-05-31"
>>   [6] "2000-06-30" "2000-07-31" "2000-08-31" "2000-09-30" "2000-10-31"
>>  [11] "2000-11-30" "2000-12-31" "2001-01-31"
>>
>>  And we do it ourself like this:
>>
>>  > as.Date(format(seq(as.Date("2000-1-1"), as.Date("2001-1-1"), 
>>"month") + 32, "%Y-%m-01"))-1
>>   [1] "2000-01-31" "2000-02-29" "2000-03-31" "2000-04-30" "2000-05-31"
>>   [6] "2000-06-30" "2000-07-31" "2000-08-31" "2000-09-30" "2000-10-31"
>>  [11] "2000-11-30" "2000-12-31" "2001-01-31"
>>
>>
>>
>>
>>  On 6/4/07, hadley wickham <h.wickham at gmail.com> wrote:
>>  > > seq(as.Date("2000-1-1"), as.Date("2001-1-1"), "months")
>>  >  [1] "2000-01-01" "2000-02-01" "2000-03-01" "2000-04-01" "2000-05-01"
>>  >  [6] "2000-06-01" "2000-07-01" "2000-08-01" "2000-09-01" "2000-10-01"
>>  > [11] "2000-11-01" "2000-12-01" "2001-01-01"
>>  >
>>  >
>  > > > seq(as.Date("2000-1-31"), as.Date("2001-1-31"), "months")
>>  >  [1] "2000-01-31" "2000-03-02" "2000-03-31" "2000-05-01" "2000-05-31"
>>  >  [6] "2000-07-01" "2000-07-31" "2000-08-31" "2000-10-01" "2000-10-31"
>>  > [11] "2000-12-01" "2000-12-31" "2001-01-31"
>>  >
>>  > Is this a bug?
>>  >
>>  > Hadley
>>  >
>>  > ______________________________________________
>>  > R-help at stat.math.ethz.ch 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.
>  > >
>  >
>
>______________________________________________
>R-help at stat.math.ethz.ch 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.


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA



More information about the R-help mailing list