time_lag {timeplyr} | R Documentation |
Time-lagged values
Description
Time-lagged values
Usage
time_lag(
x,
k = 1L,
time = seq_along(x),
g = NULL,
time_type = getOption("timeplyr.time_type", "auto"),
roll_month = getOption("timeplyr.roll_month", "preday"),
roll_dst = getOption("timeplyr.roll_dst", "NA")
)
Arguments
x |
Vector. |
k |
Lag size, must be one of the following:
|
time |
(Optional) time index. |
g |
Grouping object passed directly to |
time_type |
If "auto", |
roll_month |
Control how impossible dates are handled when
month or year arithmetic is involved.
Options are "preday", "boundary", "postday", "full" and "NA".
See |
roll_dst |
See |
Value
A vector of length(x)
lagged by a specified time unit.
Examples
library(timeplyr)
x <- 1:10
t <- time_seq(Sys.Date(), len = 10, time_by = "3 days")
dplyr::lag(x)
time_lag(x)
time_lag(x, time = t, k = "3 days")
# No values exist at t-1 days
time_lag(x, time = t, k = 1)