當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


R hms round_hms 四舍五入或截斷為秒的倍數

方便的函數是四舍五入或截斷為秒的倍數。

用法

round_hms(x, secs = NULL, digits = NULL)

trunc_hms(x, secs = NULL, digits = NULL)

參數

x

hms 類的向量

secs

秒的倍數,正數。支持小於 1 的值

digits

位數,整數。支持負數。

輸入,四舍五入或截斷為最接近的 secs 倍數

(或 digits 的數量)

例子

round_hms(as_hms("12:34:56"), 5)
#> 12:34:55
round_hms(as_hms("12:34:56"), 60)
#> 12:35:00
round_hms(as_hms("12:34:56.78"), 0.25)
#> 12:34:56.75
round_hms(as_hms("12:34:56.78"), digits = 1)
#> 12:34:56.8
round_hms(as_hms("12:34:56.78"), digits = -2)
#> 12:35:00
trunc_hms(as_hms("12:34:56"), 60)
#> 12:34:00
源代碼:R/round.R

相關用法


注:本文由純淨天空篩選整理自Kirill Müller等大神的英文原創作品 Round or truncate to a multiple of seconds。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。