0

I have a data frame with time in character format, I need to convert it into time format. I have tried using strptime and POSIXct but it adds the date also. I just need the time.

For e.g.: TRK_DEP_TIME <- c("22:00", "14:30"......) _____ character datatype

doing........ as.POSIXCT(TRK_DEP_TIME, format = %H:%M")

The result will be ("10/11/17,22:00", "10/11/17, 14:30".....)

I am looking for just the time, I don't need the date to be associated with it. Is there any way I can achieve this?

Dave2e
  • 22,192
  • 18
  • 42
  • 50

1 Answers1

0

Use chron "times" class:

library(chron)

ch <- c("22:00", "14:30") # test input (character)
times(paste0(ch, ":00"))
## [1] 22:00:00 14:30:00
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341