percentChange
Syntax
percentChange(X)
Arguments
X is a vector or a matrix.
Details
If X is a vector, for each element in X, compute the percentage change relative to the previous element. 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
percentChange([1,2,3]);
// output
[,1,0.5]
percentChange(85 90 95);
// output
[,0.058824,0.055556]
m=matrix(100 105 109 112 108 116, 200 212 208 199 206 210);
m
| #0 | #1 |
|---|---|
| 100 | 200 |
| 105 | 212 |
| 109 | 208 |
| 112 | 199 |
| 108 | 206 |
| 116 | 210 |
percentChange(m);
| #0 | #1 |
|---|---|
| 0.05 | 0.06 |
| 0.038095238095238 | -0.018867924528302 |
| 0.027522935779817 | -0.043269230769231 |
| -0.035714285714286 | 0.035175879396985 |
| 0.074074074074074 | 0.019417475728155 |
