3.5.2.8 Diff


Description

Returns a dataset that contains the difference between adjacent elements in dataset. Optional parameter n allows for padding to return N-1, N, or N+1 elements:

  • n=0: If there are N elements in dataset, the returned range will have N-1 elements. The first element in the returned range is equal to the difference between the second and the first element of the given range.
  • n=1: Pad with 0 at dataset end. Returns N elements.
  • n=2: Pad with 0 at dataset begin. Returns N elements.
  • n=3: Pad with 0 at dataset begin. Returns N+1 elements. Total all differences between N elements to obtain element N+1.
  • n= 4: Pad with NANUM at dataset begin. Returns N elements.


If option n is omitted, returns N-1 elements (the function is calculated using n = 0).

Syntax

Dataset diff(dataset vd[,n])

Parameters

ds

A dataset or a range pointing to a single dataset.

Return

Returns a dataset.

Examples

col(1) = data(1,100);
col(2) = 1.23 + 4.56 * col(1) - 7.89 * col(1) * col(1);
col(3) = diff(col(2));
col(4) = diff(col(3));
col(5) = col(4) / 2;
dataset vd = {1,-2,4,-3,1,2,5,3,-2,-1};
col(A)=diff(vd);
col(B)=diff(vd,0);
col(C)=diff(vd,1);
col(D)=diff(vd,2);
col(E)=diff(vd,3);
col(F)=diff(vd,4);