Search code examples
rdatetimetimestrptimechron

Recording timer data - how to measure milliseconds without the date?


I have a list of times in a basketball game. Here are some sample time values to show how they're stored: "11:44.0", "10:03.0", "8:35.0", "6:19.0", "0:49.9", "0:03.9"

(Minutes - no leading 0):(Seconds - with leading 0).(Tenths of a second)

It responds well to the format %M:%OS, but I end up with a whole date to go with what was just timer data. This is inconvenient mostly because it looks bad (if any graphs or tables autogenerate to include the date), and if I'm working on it over multiple days, I'll have to make sure all my values have the same date in order to subtract them properly from each other.

> strptime("0:49.9", format = "%M:%OS")
[1] "2018-08-13 00:00:49.9 EDT"

I want to keep it in a time format so it's easy to manipulate. It seems that methods of truncating (like strptime's format) turn it into a string, and I don't think the times class from chron handles milliseconds (or tenths of a second, for my case).


Solution

  • After reading different threads about this issue, I've come to the conclusion that there's no good way to represent date-time without the date. To a certain extent, all date-time formats keep track of date, at least on a basal level even if it's not displayed. Any methods (that I could find) that truly truncate it end up converting the value back to a string.

    I'll keep it in its current character format and call strptime on it whenever I need it. It will look something like:

    graph <- ggplot(data, strptime(times, format = "%M:%OS"), scores) + geomline()
    

    ggplot is good enough to automatically recognize they're all the same date, so it only displays the time. It might work to convert it to numeric, but then I'd need to measure it terms of tenths of a second (so 12:00.00 -> 7200 tenths of a second), and perform other transformations to display it in a palatable time format (easier to read "7:43" than "2570 tenths of a second into a quarter")