[R] Best way to replace :SS with :00

David Winsemius dwinsemius at comcast.net
Thu Jul 16 21:55:46 CEST 2009


Have you looked at the chron package? It has a trunc.times function:

??"times"    # would have shown this to you

And the help page appears to provide exactly what was requested.


---------puzzlement follows--------
I did get somewhat unexpected results when I applied what seems to be  
the obvious modification to the first example on the chron function  
help page:

 > x <- chron(dates = dts, times = tms, format= c(dates = "m/d/y",  
times = "h:m") )
 > x
[1] (02/27/92 2303) (02/27/92 2229) (01/14/92 0103) (02/28/92 1821)  
(02/01/92 1656)

Notice that the semicolon is missing. It's not missing when I use a  
full "h:m:s"

 > x <- chron(dates = dts, times = tms, format= c(dates = "m/d/y",  
times = "h:m:s") )
 > x
[1] (02/27/92 23:03:20) (02/27/92 22:29:56) (01/14/92 01:03:30)  
(02/28/92 18:21:03)
[5] (02/01/92 16:56:26)

But it comes back with "h:m:"

 > x <- chron(dates = dts, times = tms, format= c(dates = "m/d/y",  
times = "h:m:") )
 > x
[1] (02/27/92 23:03:) (02/27/92 22:29:) (01/14/92 01:03:) (02/28/92  
18:21:) (02/01/92 16:56:)


-- 
David

On Jul 16, 2009, at 3:25 PM, Jason Rupert wrote:

>
> Not sure if there is an R way to do this or a regular express way,  
> but here is what I am trying to do.
>
> I've got lots of data where the format is HH:MM:SS, but I need to  
> format it like HH:MM:00, i.e. round the second down to zero.
>
> What is the best way to do this?
>
> Thanks again.
>
> Jason
>

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list