将 minutes:seconds:miliseconds 的因数转换为毫秒
Convert factor of minutes:seconds:miliseconds to miliseconds
我有一列时间,它们作为因素存在于一列中,格式如下 1:38.109
(即 1 分钟 38 秒 109 毫秒)
如何在 R 中将其转换为单个连续变量(即 98109 毫秒)?
谢谢!
library(lubridate)
test <- data.frame(time_fac = c("1:38.109", "2:01.302", "0:23.12", "0:01"))
test$time_ms = as.numeric(lubridate::ms(as.character(test$time_fac)))*1000
as.character
用于在lubridate::ms
获取时间格式的时间之前将因子变量time_fac
转换为字符,转换为数字(以秒为单位)和乘以 1000 得到以毫秒为单位的时间。
> test
time_fac time_ms
1 1:38.109 98109
2 2:01.302 121302
3 0:23.12 23120
4 0:01 1000
我有一列时间,它们作为因素存在于一列中,格式如下 1:38.109
(即 1 分钟 38 秒 109 毫秒)
如何在 R 中将其转换为单个连续变量(即 98109 毫秒)?
谢谢!
library(lubridate)
test <- data.frame(time_fac = c("1:38.109", "2:01.302", "0:23.12", "0:01"))
test$time_ms = as.numeric(lubridate::ms(as.character(test$time_fac)))*1000
as.character
用于在lubridate::ms
获取时间格式的时间之前将因子变量time_fac
转换为字符,转换为数字(以秒为单位)和乘以 1000 得到以毫秒为单位的时间。
> test
time_fac time_ms
1 1:38.109 98109
2 2:01.302 121302
3 0:23.12 23120
4 0:01 1000