glag: Lag a vector or a matrix, with special treatment of zoo...

Description Usage Arguments Value Note Author(s) See Also Examples

View source: R/glag.R

Description

Similar to the lag function from the stats package, but glag enables padding (e.g. NAs or 0s) of the lost entries. Contrary to the lag function in the stats package, however, the default in glag is to pad (with NAs). The glag is particularly suited for zoo objects, since their indexing is retained

Usage

1
glag(x, k = 1, pad = TRUE, pad.value = NA)

Arguments

x

a numeric vector or matrix

k

integer equal to the lag (the default is 1)

pad

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

pad.value

the pad-value

Value

A vector or matrix with the lagged values

Note

Empty

Author(s)

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

See Also

lag, gdiff, diff

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
##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)

lgarch documentation built on May 29, 2017, 9:08 a.m.