For a vector or list of times, I would like to switch from string time, for example. 12:34:56.789 to the millisecond from midnight, which will be equal to 45296789 .
Here is what I am doing now:
toms = function(time) { sapply(strsplit(time, ':', fixed = T), function(x) sum(as.numeric(x)*c(3600000,60000,1000))) }
and would like to do it faster.
Here is an example dataset for comparison:
times = rep('12:34:56.789', 1e6) system.time(toms(times))
source share