[R] Building a vector of dates between extreme dates
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Thu Jun 23 13:24:37 CEST 2005
Prof Brian Ripley <ripley at 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 at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list