glag {gfunctions}R Documentation

Lag a vector or a matrix, with special treatment of zoo and ts objects

Description

The glag() function is similar to the lag() function from the stats package, but glag() actually lags (the default in lag() is to lead). The funtion glag() also enables padding (for example NAs or 0s) of the lost entries. Contrary to the lag() function, however, the default in glag() is to pad (with NAs). The glag() is particularly suited for zoo objects, since their indexing is retained. The prefix g is a reminder of who to blame if things do not work properly.

Usage

## generic:
glag(x, ...)
## Default S3 method:
glag(x, k = 1, pad = TRUE, pad.value = NA, ...)

Arguments

x

a numeric vector or matrix, or objects of class zoo or ts.

k

integer equal to the lag (the default is 1). Negative values (that is, 'leading') is not possible.

pad

logical. If TRUE (default), then the lost entries are padded with pad.value. If FALSE, then no padding is undertaken.

pad.value

the padding value.

...

additional arguments

Value

A vector or matrix, or objects of class zoo or ts, with the lagged values.

Author(s)

Genaro Sucarrat, http://www.sucarrat.net/

See Also

lag(), lag.zoo()

Examples

##lag series with NA for the missing entries:
x <- rnorm(5)
glag(x)

##lag series with no padding:
x <- rnorm(5)
glag(x, pad = FALSE)

##lag series and retain the original zoo-index ordering:
x <- as.zoo(rnorm(5))
glag(x)

##lag two periods:
glag(x, k = 2)


[Package gfunctions version 1.0 Index]