[R] time conversions

peter dalgaard pdalgd at gmail.com
Wed Feb 18 20:14:49 CET 2015


> On 18 Feb 2015, at 18:45 , Troels Ring <tring at gvdnet.dk> wrote:
> 
> dear friends - sorry to ask another simple question -
> I have dates set up as this:
> dates  #[1] 2003-01-21 01:08:00
> 
> To handle it I did
> as.POSIXlt(dates)  "2003-01-21 01:08:00 CET"
> 
> but noticed that during write.table it was apparently better to take it further
> as.numeric(as.POSIXct(as.POSIXlt(dates))   1043107680
> 
> And this works fine for modeling but now I would like to have it back as POSIXlt
> as.POSIXlt requires an origin, if I'm right.
> So how is it done?

Like this?

> as.POSIXlt(1043107680, origin='1970-1-1')
[1] "2003-01-21 01:08:00 CET"

(Time zones may require special care, though.)

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list