deltas
Syntax
deltas(X)
Arguments
X is a scalar/vector/matrix.
Details
If X is a vector, return a vector containing the subtractions between adjacent elements. The first element of the result is always NULL.
If X is a matrix, conduct the aforementioned calculation within each column of X. The result is a matrix with the same shape as X.
Examples
$ x=7 4 5 8 9;
$ deltas(x);
[,-3,1,3,1]
// equivalent to [, 4-7, 5-4, 8-5, 9-8]
$ x=NULL 1 2 NULL 3;
$ deltas(x);
[,,1,,]
$ m=matrix(1 3 2 5 6, 0 8 NULL 7 6);
$ m;
#0 |
#1 |
---|---|
1 |
0 |
3 |
8 |
2 |
|
5 |
7 |
6 |
6 |
$ deltas(m);
#0 |
#1 |
---|---|
2 |
8 |
-1 |
|
3 |
|
1 |
-1 |