Description Usage Arguments Value Note Author(s) See Also Examples
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
1 |
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 |
A vector or matrix with the differenced values
Empty
Genaro Sucarrat, http://www.sucarrat.net/
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.