I have a vector with time information and a date noted only once per day. I need to convert the vector into a usable format such as POSIXlt
. The times are ordered, where all times (%H:%M
) within a day belong to the last date noted before the date-less time.
t <- structure(c(6L, 1L, 2L, 3L, 4L, 5L, 10L, 7L, 8L, 9L),
.Label = c("00:15", "00:25", "00:35", "00:45", "02:05", "20.01.2013; 0:05",
"20:48", "20:58", "21:08", "25.01.2013; 20:38"), class = "factor")
From multiple previous answers to questions about factor to date conversion (e.g. here), I know how to convert t[c(1, 7)]
.
t1 <- strptime(as.character(t[c(1, 7)]), format = "%d.%m.%Y; %H:%M")
# t1
# [1] "2013-01-20 00:05:00 CET" "2013-01-25 20:38:00 CET"
However, how can I propagate the missing date for the remaining values so that they would convert correctly?