-4

How can I change this to numeric values, the number refers to the record of the 1.5km running, containing min:sec:one-tenth of seconds

"4:04.86"  -> 4:04.86

as.numeric function is not working in this case, I think, its because of ':'

Jaap
  • 81,064
  • 34
  • 182
  • 193
Hung
  • 1
  • 4

2 Answers2

6

Here's a way with lubridate that gives the result in seconds.

library(lubridate)
x <- "4:04.86"
period_to_seconds(ms(x))
# [1] 244.9
Matthew Plourde
  • 43,932
  • 7
  • 96
  • 113
3

Base R can handle this a-okay too, using ?as.difftime:

as.difftime("4:04.86", format="%M:%OS")
#Time difference of 4.081 mins

as.difftime("4:04.86", format="%M:%OS", units="secs")
#Time difference of 244.86 secs
thelatemail
  • 91,185
  • 12
  • 128
  • 188