View source: R/round.POSIXlt.R
round.POSIXlt | R Documentation |
There are round
methods in base for objects of DateTimeClasses
. However, they can only round to full second, minutes, hours, and days. These functions offer some more options.
## S3 method for class 'POSIXlt' round(x, digits = c("mins", "5mins", "10mins", "15mins", "quarter hours", "30mins", "half hours", "hours")) ## S3 method for class 'POSIXct' round(x, ...)
x |
A |
digits |
Either a character string specifying the time units to round to (see choices above) or a numeric specifying the minutes to round to. To go to seconds just use values < 1, to go beyond the hour just use values > 60. |
... |
Further arguments to methods. |
A POSIXct
object with rounded, not truncated date times.
Gerald Jurasinski, gerald.jurasinski@uni-rostock.de,
borrowing heavily from https://stat.ethz.ch/pipermail/r-help/2012-June/315336.html
# Current time in GMT and as class "POSIXlt" zlt <- as.POSIXlt(Sys.time(), "GMT") # Same time as class POSIXct zct <- as.POSIXct(zlt) # round to minute round(zct) # round to half hour round(zct, "30mins") round(zct, "half hour") round(zct, 30) # round to 20 minutes round(zlt, 20) # round to 30 seconds round(zlt, 0.5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.