Learn R Programming

matrixStats (version 0.51.0)

rowDiffs: Calculates difference for each row (column) in a matrix

Description

Calculates difference for each row (column) in a matrix.

Usage

rowDiffs(x, rows=NULL, cols=NULL, lag=1L, differences=1L, ...)
 colDiffs(x, rows=NULL, cols=NULL, lag=1L, differences=1L, ...)

Arguments

x
rows, cols
A vector indicating subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.
lag
An integer specifying the lag.
differences
An integer specifying the order of difference.
...
Not used.

Value

Returns a numeric Nx(K-1) or (N-1)xK matrix.

See Also

See also diff2().

Examples

Run this code
x <- matrix(1:27, ncol=3)

d1 <- rowDiffs(x)
print(d1)

d2 <- t(colDiffs(t(x)))
stopifnot(all.equal(d2, d1))

Run the code above in your browser using DataLab