Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

round_hms

Round or truncate to a multiple of seconds


Description

Convenience functions to round or truncate to a multiple of seconds.

Usage

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

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

Arguments

x

A vector of class hms

secs

Multiple of seconds, a positive numeric. Values less than one are supported

digits

Number of digits, a whole number. Negative numbers are supported.

Value

The input, rounded or truncated to the nearest multiple of secs (or number of digits)

Examples

round_hms(as_hms("12:34:56"), 5)
round_hms(as_hms("12:34:56"), 60)
round_hms(as_hms("12:34:56.78"), 0.25)
round_hms(as_hms("12:34:56.78"), digits = 1)
round_hms(as_hms("12:34:56.78"), digits = -2)
trunc_hms(as_hms("12:34:56"), 60)

hms

Pretty Time of Day

v1.0.0
MIT + file LICENSE
Authors
Kirill Müller [aut, cre], R Consortium [fnd], RStudio [fnd]
Initial release
2021-01-13

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.