[R] Problem with seq.dates in chron
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Sep 3 18:26:44 CEST 2004
The following naive calculation in seq.dates explains this:
to <- from + (length. - 1) * c(1, 7, 31, 366)[i]
It is calculating the end date from 31-day months.
The following is correct (and even readable to those unused to such an
illogical date format) in Dates in base R.
> startdatetime <- as.Date("1995-01-01")
> seq(as.Date("1995-01-01"), by="months", length=129)
On Fri, 3 Sep 2004, Waichler, Scott R wrote:
>
> I get faulty output from seq.dates() if I specify a length that is too
> long.
> For example, I ask for 129 months in the following call to the function,
> but it returns
> 131:
>
> > R.version.string
> [1] "R version 1.9.1, 2004-06-21"
> > startdatetime <- chron(dates="01/01/1995", times="00:00:00")
> > beg.month.datetimes <- seq.dates(from=startdatetime, by="months",
> length=129)
> > beg.month.datetimes
> [1] 01/01/95 02/01/95 03/01/95 04/01/95 05/01/95 06/01/95 07/01/95
> 08/01/95
> [9] 09/01/95 10/01/95 11/01/95 12/01/95 01/01/96 02/01/96 03/01/96
> 04/01/96
> [17] 05/01/96 06/01/96 07/01/96 08/01/96 09/01/96 10/01/96 11/01/96
> 12/01/96
> [25] 01/01/97 02/01/97 03/01/97 04/01/97 05/01/97 06/01/97 07/01/97
> 08/01/97
> [33] 09/01/97 10/01/97 11/01/97 12/01/97 01/01/98 02/01/98 03/01/98
> 04/01/98
> [41] 05/01/98 06/01/98 07/01/98 08/01/98 09/01/98 10/01/98 11/01/98
> 12/01/98
> [49] 01/01/99 02/01/99 03/01/99 04/01/99 05/01/99 06/01/99 07/01/99
> 08/01/99
> [57] 09/01/99 10/01/99 11/01/99 12/01/99 01/01/00 02/01/00 03/01/00
> 04/01/00
> [65] 05/01/00 06/01/00 07/01/00 08/01/00 09/01/00 10/01/00 11/01/00
> 12/01/00
> [73] 01/01/01 02/01/01 03/01/01 04/01/01 05/01/01 06/01/01 07/01/01
> 08/01/01
> [81] 09/01/01 10/01/01 11/01/01 12/01/01 01/01/02 02/01/02 03/01/02
> 04/01/02
> [89] 05/01/02 06/01/02 07/01/02 08/01/02 09/01/02 10/01/02 11/01/02
> 12/01/02
> [97] 01/01/03 02/01/03 03/01/03 04/01/03 05/01/03 06/01/03 07/01/03
> 08/01/03
> [105] 09/01/03 10/01/03 11/01/03 12/01/03 01/01/04 02/01/04 03/01/04
> 04/01/04
> [113] 05/01/04 06/01/04 07/01/04 08/01/04 09/01/04 10/01/04 11/01/04
> 12/01/04
> [121] 01/01/05 02/01/05 03/01/05 04/01/05 05/01/05 06/01/05 07/01/05
> 08/01/05
> [129] 09/01/05 10/01/05 11/01/05
> >
>
> Is this a bug, and can it be fixed?
>
> Scott Waichler
> Pacific Northwest National Laboratory
> scott.waichler<at>pnl.gov
>
> ______________________________________________
> 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
>
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list