Description Usage Arguments Value Examples
Returns for (each of) the given timestamp(s) the timestamp(s) itself if it represents a multiple of the given time step or the nearest smaller or nearest greater timestamp that represents a multiple of the time step.
1 | roundTime(tstamp, tstep, direction = -1)
|
tstamp |
(vector of) timestamp(s) of class "POSIXlt" or "POSIXct" |
tstep |
time step in seconds of which timestamps in tstamp shall represent multiples |
direction |
one of -1, 0, 1. If -1, the nearest timestamp (either smaller or greater) complying with the timestamp is returned. If 0, always the nearest greater timestamp and if 1, always the nearest smaller timestamp is returned. |
(Vector of) timestamp(s) corresponding to timestamp(s) given in tstamp being “rounded” to the nearest — greater or smaller (direction == -1), always smaller (direction == 1) or always greater (direction == 0) — timestamp representing a multiple of the given time step tstep.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # Generate a timestamp to be "rounded"
t0 <- hsToPosix("2011-12-24 18:22:05")
# Round to nearest (default) full minute
roundTime(t0, 60) ## = 2011-12-24 18:22:00 UTC
# Round to nearest full greater minute
roundTime(t0, 60, 0) ## = 2011-12-24 18:23:00 UTC
# Round to nearest multiple of 15 minutes (-1 could be omitted)
roundTime(t0, 15*60, -1) ## 2011-12-24 18:15:00 UTC
# Round to nearest smaller multiple of four hours
roundTime(t0, 4*60*60, 1) ## 2011-12-24 16:00:00 UTC
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.