Lag | R Documentation |
Shifts a vector shift
elements later. Character or factor variables
are padded with ""
, numerics with NA
. The shift may be
negative.
Lag(x, shift = 1)
x |
a vector |
shift |
integer specifying the number of observations to be shifted to the right. Negative values imply shifts to the left. |
Attributes of the original object are carried along to the new lagged one.
a vector like x
.
Frank E Harrel Jr
<https://CRAN.R-project.org/package=Hmisc>
lag
Lag(1:5,2)
Lag(letters[1:4],2)
Lag(factor(letters[1:4]),-2)
# Find which observations are the first for a given subject
id <- c('a','a','b','b','b','c')
id != Lag(id)
!duplicated(id)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.