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:
data <- c("11:14", "17:27", "25:34", "39:17", "39:59", "42:32", "50:15", "50:53", "64:22", "67:39")
My issue arises from the fact that minutes exceed 60 (they can be between 0 and 90 minutes). So essentially, I would like code that would print out the intervals between the events:
"6:13", "8:07", "13:43",..., "3:17"
Would it be better to convert the data into hours and then go from there? Just an idea I had to make it easier. I've had a look at other questions, but I couldn't find any that had been asked for R. If it has and I missed it, feel free to criticize but please link me the duplicate.
Thanks in advance!
This might work too
Another base R attempt using
as.difftime
to specify the units explicitly:Look into lubridate for this kind of thing.
There's probably an easier way to do it, but this works:
If you want the output as a formatted string instead of a period, use sprintf: