Re: [R] Extract time only from POSIXlt object

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Sun, 30 Jan 2011 00:08:14 -0500

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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sun 30 Jan 2011 - 05:15:07 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 30 Jan 2011 - 10:20:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive