gdiff: Difference a vector or a matrix, with special treatment of...

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

View source: R/gdiff.R

Description

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

Usage

1
gdiff(x, lag = 1, pad = TRUE, pad.value = NA)

Arguments

x

a numeric vector or matrix

lag

integer equal to the difference-length (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

numeric. The pad-value

Value

A vector or matrix with the differenced values

Note

Empty

Author(s)

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

See Also

diff, glag, lag

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
##1st difference of a series:
x <- rnorm(5)
gdiff(x)

##1st difference with no padding:
gdiff(x, pad=FALSE)

##1st difference retaining the original zoo-index ordering:
gdiff(as.zoo(x))

##1st difference of a matrix:
y <- matrix(rnorm(8),4,2)
gdiff(y)

##2nd difference of the same matrix:
gdiff(y, lag=2)

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