Skip to contents

Differences between Matrix Rows

Usage

diffrows(x)

Arguments

x

matrix

Value

matrix with one row less than in input matrix x and each row

i representing the difference x[i+1, ]-x[i, ] between rows

i+1 and i in x

Examples

x <- matrix(1:12, nrow = 3)

d <- diffrows(x)

x[2, ] - x[1, ] == d[1, ]
#> [1] TRUE TRUE TRUE TRUE
x[3, ] - x[2, ] == d[2, ]
#> [1] TRUE TRUE TRUE TRUE