有没有办法将 mm:ss.00 转换为 seconds.00?
问题描述:
我有一些 mm:ss.00 格式(即 02:15.45 或 00:34.58)的性能时间数据.R 将变量识别为一个因素,但我想将每个性能时间转换为几秒(即 02:15.45 到 135.45).我一直在寻找答案,但似乎无法找到使它起作用的方法.提前致谢.
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 time to just seconds (i.e. 02:15.45 to 135.45). I've searched for an answer but can't seem to find a way to make it work. Thanks in advance.
答
使用 lubridate 包(tidyverse 的一部分):
Using lubridate package (part of tidyverse):
library(lubridate)
period_to_seconds(hms("12:12:54"))