[R] Extract time only from POSIXlt object
David Winsemius
dwinsemius at comcast.net
Sun Jan 30 06:08:14 CET 2011
On Jan 29, 2011, at 7:45 PM, Simon Goodman wrote:
>
> How can I extract only the time component from an POSIXlt object?
>
> For example if I try the following it still returns both the date and
> time...
>
>> as.POSIXlt(tr.date[1])
> [1] "2010-10-18 21:46:53"
>> as.POSIXlt(tr.date[1],"%H:%M:%S")
> [1] "2010-10-18 21:46:53"
>
> round and trunc don't help... is there an "as.Time" equivalent to
> as.Date
> ?
> ptime <- as.POSIXlt("2010-10-18 21:46:53")
> ptime
[1] "2010-10-18 21:46:53"
> format(ptime, format="%H:%M:%S")
[1] "21:46:53"
This is a character value, no longer a time.
--
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list