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

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Thu 23 Jun 2005 - 21:24:37 EST

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)

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@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
Received on Thu Jun 23 21:26:58 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:58 EST