[R] converting from numeric to Date

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Nov 23 18:49:57 CET 2006


"COMTE Guillaume" <g.comte at alliance-ir.net> writes:

> Hi all,
> 
> I have a Date, that has been converted to a number that represent the
> count of seconds since year 1970, how do i convert it to a date ?

> Example :

> >Limite_x<-c(1131408000,1163548800)
> 
> >is(limite_x)
> 
> [1] "numeric" "vector"

Not really:

> is(limite_x)
Error in .class1(object) : object "limite_x" not found

(Point being that you should be careful when citing R output that it
really is feasible output.)

> But these numbers are dates, did R provide something that give you the
> date from this numeric vector ?

Just add the origin:

> Limite_x + ISOdatetime(1970,1,1,0,0,0)
[1] "2005-11-08 CET" "2006-11-15 CET"

or (watch it!)

> Limite_x/24/3600 + as.Date("1970-1-1")
[1] "2005-11-08" "2006-11-15"

-- 
   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