lastNot
Syntax
lastNot(X, [k])
Arguments
X is a vector or a matrix.
k is a scalar. It is an optional argument.
Details
If X is a vector:
If k is not specified: return the last element of X that is not NULL.
If k is specified: return the last element of X that is neither k nor NULL.
If X is a matrix, conduct the aforementioned calculation within each column of X. The result is a vector.
Examples
$ lastNot(1 6 0 0 0, 0);
6
$ lastNot(1 6 0 0 0 2 3 0 NULL, 0);
3
$ lastNot(1 6 0 0 0 2 3 0 NULL);
0
$ t=table(1 1 1 1 1 2 2 2 2 2 as id, 1 2 0 0 0 3 NULL NULL 0 0 as x);
$ t;
id |
x |
---|---|
1 |
1 |
1 |
2 |
1 |
0 |
1 |
0 |
1 |
0 |
2 |
3 |
2 |
|
2 |
|
2 |
0 |
2 |
0 |
select lastNot(x, 0) from t group by id;
id |
lastNot_x |
---|---|
1 |
2 |
2 |
3 |
$ m=matrix(2 NULL 1 0 NULL, NULL 2 NULL 6 0);
$ m;
#0 |
#1 |
---|---|
2 |
2 |
1 |
|
0 |
6 0 |
$ lastNot(m, 0);
[1,6]