I have a dataset which contains the timing of events in football. A game exceeds 60 minutes, and I\'m trying to calculate intervals. This is the data I have:
dat
Look into lubridate for this kind of thing.
There's probably an easier way to do it, but this works:
library(lubridate)
data <- c("11:14", "17:27", "25:34", "39:17", "39:59", "42:32", "50:15", "50:53", "64:22", "67:39")
out <- seconds_to_period(diff(as.numeric(ms(data)))
If you want the output as a formatted string instead of a period, use sprintf:
sprintf('%02d:%02d', minute(out), second(out))