[R] Best way to Convert String to Time for comparison?

Gabor Grothendieck ggrothendieck at gmail.com
Wed Aug 4 14:47:17 CEST 2010


On Wed, Aug 4, 2010 at 8:43 AM, allany <allany at cmu.edu> wrote:
>
> Hi guys,
>
> I have a large text file with a bunch of Time in "HH:MM" format, what would
> be the best way to process it into a Time Object so that I can use
> comparisons like (1:00<"1:15") or (13:00>"2:00") to both return true.
>
> Right now if I do a comparison like (3:00 < "1:59") I get a true, but if I
> do (3:00 < "2:00") I get false, which is an obvious error.
>
>

Try this:

library(chron)
t1 <- times(paste("13:00", "00", sep = ":"))
t2 <- times(paste("2:00", "00", sep = ":"))
t1 > t2



More information about the R-help mailing list