Description Usage Arguments Details Value See Also Examples
Lag a vector with respect to time order
1 |
x |
vector of values to be lagged |
id |
identifies clusters within which lagging takes place |
time |
time variable for lagging, generally integer valued |
lag |
period for lagging: lag = 1 reaches one unit of |
at |
uses the value of |
check |
that |
idx |
for compatibility with a previous version. |
The function can also be called as Lag
which is now deprecated
to avoid conflicts with Hmisc::Lag
. Use cLagI
for intra(extra)polative lagging.
A vector of values of x
lagged within levels of id
. The value returned at time == t
is the value
of x
at time == t-1
. If there is no observation for which time == t-1
then the returned value is
NA
. To lag to the previous value of time
, one can use rank
.
Consider, also, cLagI
that intrapolates backwards one unit of time
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (x, id = rep(1, length(x)), time = 1:length(x), lag = 1,
at = NULL, check = T, idx)
{
if (check) {
comb <- paste(id, time)
if (any(duplicated(comb)))
stop("id not unique in each level of time")
}
if (!missing(idx))
time = idx
ret <- x
names(ret) <- paste(id, time, sep = "::")
retnn <- if (is.null(at))
paste(id, time - lag, sep = "::")
else paste(id, at, sep = "::")
ret[retnn]
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.