[R] Convert numeric value to POSIXct

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Thu Jan 23 00:23:06 CET 2003


You can't safely.  Why do you want to do this?

If there is a good reason,

   structure(ddd, class=c("POSIXt", "POSIXct"))

will work currently, with no guarantees for the future.

On Wed, 22 Jan 2003, Matt Pocernich wrote:

> How do I convert a numeric value indicating the time since 1970, back into
> a POSIXct class object?  I have tried format.POSIXct and as.POSIXct
> without success.
> 
> For example
> > ccc
> [1] "1945-01-01 15:00:00 MDT"
> > ddd<- as.numeric(ccc);
> > ddd
> [1] -788842800
> > format.POSIXct(ddd)
> Error in format.POSIXct(ddd) : wrong class
> > as.POSIXct(ddd)
> Error in as.POSIXct.default(ddd) : Don't know how to convert `ddd' to
> class "POSIXct"

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




More information about the R-help mailing list