r - R - 如何将十进制转换为 MM:SS.XXX
问题描述
如何使用 R 将 SS.xxx (Seconds.Milliseconds) 转换为 MM:SS.xxx (Minutes:Seconds.Milliseconds)?
例如,我的输入是
time = 92.180
我想要的输出是
time = 01:32.180
所有时间字段都有 3 个小数位。
解决方案
一个选项是 lubridate 包 - 因为您没有指定输出类,所以我包括了一些可能的输出:
package(lubridate)
t <- 92.180
# your output string as character
lubridate::seconds(t) %>%
lubridate::as_datetime() %>%
format("%M:%OS3")
# output as period
lubridate::seconds(t) %>%
lubridate::as.period()
# output as duration
lubridate::seconds(t) %>%
lubridate::as.duration()
# output as time time
lubridate::seconds(t) %>%
lubridate::as.difftime()
推荐阅读
- c# - ASP.NET 与 IFream 中的 .aspx 页面共享相同的会话
- reporting-services - 如何解决重报告的 SSRS 超时问题
- r - 将一列设置为行 ID 然后将其删除的问题
- oracle - 您如何在 Oracle 中按此分组?
- python - ValueError:密集层的输入 0 与层不兼容:预期轴 -1。张量流
- pandas - 使用 groupby 创建新的数据框
- c# - 错误请求 - 无效的主机名 ASP.net Visual Studio 2019
- wordpress - Wordpress 图片上传质量好问题
- c++ - 如何在数组上存储多个 uri 值?
- reactjs - 如何在反应谷歌地图中从绘图管理器中提取数据?