Is there a way to convert mm:ss.00 to seconds.00?

前端 未结 6 1774
离开以前
离开以前 2020-12-30 03:12

I\'ve got some performance time data in mm:ss.00 format (i.e. 02:15.45, or 00:34.58). R is recognizing the variable as a factor, but I\'d like to convert each performance t

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-30 03:43

    Look into strptime. Specifically

    t = "02:15.45"
    (as.numeric(as.POSIXct(strptime(t, format = "%M:%OS"))) - 
        as.numeric(as.POSIXct(strptime("0", format = "%S"))))
    

    This will work, but is possibly a little awkward (doing it this way mostly because of POSIXct's annoying automatic unit conversion...)

提交回复
热议问题