[R] Generating date variables

Joerg Maeder joerg.maeder at ethz.ch
Thu Nov 15 10:37:12 CET 2001


Hello,

one way is
#generate a date sequence
a <- seq(ISOdate(2001,1,1,0), ISOdate(2001,12,31,0),"days")
#extract the part that is neede (date, without time)
a <- strptime(as.character(a),format="%Y-%m-%d")
#convert it to the wished format
strftime(a,format="%m/%d/%Y")

gruess

joerg

Mark Scarr wrote:
> 
> Hi there,
> 
> I would like to generate a vector of dates
> to plot on a graph (i.e a string vector)
> for example 05/04/2001 would be 4th May 2001
> (American format).
> I need to do this for a complete year, taking into
> account number of days in the month, leap year etc...
> Is there an easy way to do this in R?
> 
> Any help would be most appreciated.
> 
> Regards,
> 
> Mark.
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

-- 
    Joerg Maeder             IACETH              INSTITUTE
   PhD Student                              FOR ATMOSPHERIC 
  Phone: +41 1 633 36 25                 AND CLIMATE SCIENCE
 Fax: +41 1 633 10 58                  ETH ZÜRICH Switzerland
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list