I entered my data by hand, and to save time I didn\'t include any punctuation in my times. So, for example, 8:32am I entered as 832. 3:34pm I entered as 1534. I\'m trying to
I thought I'd throw out a non-regex solution that uses lubridate
. This is probably overkill.
library(lubridate)
library(stringr)
time.orig <- c('834', '1534')
# zero pad times before noon
time.padded <- str_pad(time.orig, 4, pad="0")
# parse using lubridate
time.period <- hm(time.padded)
# make it look like time
time.pretty <- paste(hour(time.period), minute(time.period), sep=":")
And you end up with
> time.pretty
[1] "8:34" "15:34"