我正在try 将3700等数字转换成分钟和秒的格式,即61:40.
我发现了以下问题,如果时间不到一小时,这基本上就是我想要的,但对于我的示例3700,它基本上会重置为01:40
How to convert int to minutes and seconds with R
谁能告诉我如何修改代码才能到达我想要的61:40.
我正在try 将3700等数字转换成分钟和秒的格式,即61:40.
我发现了以下问题,如果时间不到一小时,这基本上就是我想要的,但对于我的示例3700,它基本上会重置为01:40
How to convert int to minutes and seconds with R
谁能告诉我如何修改代码才能到达我想要的61:40.
您可以使用lubridate
包:
library(lubridate)
as.period(as.period(3700), 'minutes')
[1] "61M 40S"
如果你需要它作为61:40
,那么使用str_Replace_all
a <- as.period(as.period(3700), 'minutes')
stringr::str_replace_all(a, c(M=":", S = "", " " = ""))
[1] "61:40"