# Re: [R] Building a vector of dates between extreme dates

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Thu 23 Jun 2005 - 21:29:20 EST

On Thu, 23 Jun 2005, Peter Dalgaard wrote:

> Prof Brian Ripley <ripley@stats.ox.ac.uk> writes:
>
>> Use seq.POSIXct (or seq.Date since you seem to have dates and not
>> date-times), in just the same way you would use seq() for numbers.
>
> Hmm, not quite. I have to admit that the thought didn't even occur to
> me, but
>
>
>> seq(from=as.Date("2005-06-01"), to=as.Date("2005-06-30"))
> Error in seq.Date(from = as.Date("2005-06-01"), to = as.Date("2005-06-30")) :
> exactly two of 'to', 'by' and 'length.out' / 'along.with' must be specified
>
> For some odd reason, by=1 needs to be given explicitly:
>
>> seq(from=as.Date("2005-06-01"), to=as.Date("2005-06-30"), by=1)
> [1] "2005-06-01" "2005-06-02" "2005-06-03" "2005-06-04" "2005-06-05"
> [6] "2005-06-06" "2005-06-07" "2005-06-08" "2005-06-09" "2005-06-10"
> [11] "2005-06-11" "2005-06-12" "2005-06-13" "2005-06-14" "2005-06-15"
> [16] "2005-06-16" "2005-06-17" "2005-06-18" "2005-06-19" "2005-06-20"
> [21] "2005-06-21" "2005-06-22" "2005-06-23" "2005-06-24" "2005-06-25"
> [26] "2005-06-26" "2005-06-27" "2005-06-28" "2005-06-29" "2005-06-30"
>
> or, of course, you don't really need keyword matching:
>
>> seq(as.Date("2005-06-01"), as.Date("2005-06-30"), 1)

Yes, because time units are needed: for POSIXct you also have to decide if you need days or DSTdays.

```--
Brian D. Ripley,                  ripley@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

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help