cumcount

Syntax

cumcount(X)

Arguments

X is a scalar/vector.

Details

If X is a vector, cumulatively calculate the number of non-NULL elements in X. The result is a vector of the same length as X.

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=[1,2,NULL,3,4,NULL,5,6]
$ cumcount(x);
[1,2,2,3,4,4,5,6]

$ m=matrix(1 2 3 NULL 4, 5 6 NULL NULL 8);
$ m;

#0

#1

1

5

2

6

3

4

8

$ cumcount(m);

#0

#1

1

1

2

2

3

2

3

2

4

3