我有一列时间,它们以以下格式的1:38.109列中的因子存在(即1分38秒和109毫秒)
如何将其转换为R中的单个连续变量(即98109毫秒)?
谢谢!
发布于 2019-10-01 09:23:43
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)))*1000as.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 1000https://stackoverflow.com/questions/58176948
复制相似问题