I have a large data set (as a data.table,more than 100 million rows) and wish to calculate the difftime between two column.and the time string format if "%H%M%OS",without leading zeros.eg,data
ID time0 time1
1 93005220 93005320
2 93551060 93553940
3 93717740 93717740
4 94840800 94840800
5 94959510 94959510
6 101030460 101127870
7 101425010 101425010
8 104728320 104728980
9 105704050 105705890
10 135109830 135402830
11 93005220 150001330
Take the first row as example,I can not use difftime
,strptime
to calculate the difftime between "93005320"("09:30:05.320") and "93005220"("09:30:05.220"),I have to change "93005220" to the format like "093005.220",then I tried as:
difftime(strptime("093005.220","%H%M%OS"),strptime("093005.320","%H%M%OS"))
But if do like this, is too slow for more than 100 million rows. Is there an efficient way to do this in R?