I am looking for an efficient measure to calculate the differential hours between times for a given date. My data looks as follows:
Time_formatted Date Hours_diff
1/20/2016 19:19 1/20/2016 0:46
1/20/2016 18:33 1/20/2016 2:43
1/20/2016 15:50 1/20/2016 1:28
1/20/2016 14:22 1/20/2016 1:50
1/20/2016 12:32 1/20/2016 4:52
1/20/2016 7:40 1/20/2016 0
1/19/2016 23:23 1/19/2016
1/19/2016 23:06 1/19/2016
1/19/2016 22:37 1/19/2016
1/19/2016 21:56 1/19/2016
1/19/2016 21:05 1/19/2016
1/19/2016 17:53 1/19/2016
1/19/2016 17:39 1/19/2016
1/19/2016 17:01 1/19/2016
1/19/2016 15:31 1/19/2016
My first thought was to use the ave
function in R:
ave(data$Time_formatted, data$Date, FUN=difftime)
but an obvious error, Error in as.POSIXct(time2) : argument "time2" is missing, with no default
occurs by using this function. A loop will be inefficient as the data is quite large.
Any ideas to approach this kind of problem?