mlastNot
Syntax
mlastNot(X, window, [k=NULL], [minPeriods=1])
Please see mFunctions for the parameters and windowing logic.
Arguments
k (optional) is a numeric or string scalar indicating the value to be matched.
Details
If X is a vector:
-
If k is not specified, return the last element of X that is not NULL in a sliding window.
-
If k is specified, return the last element of X that is neither k nor NULL in the window.
If X is a matrix or table, conduct the aforementioned calculation within each column of X. The result is a matrix or table.
Examples
mlastNot(NULL 2 NULL 4 5, 2)
// output: [,2,2,4,5]
mlastNot(X=matrix(1..5,2..6,3..7), window=2, k=4, minPeriods=2)
#0 | #1 | #2 |
---|---|---|
|
||
2 | 3 | 3 |
3 | 3 | 5 |
3 | 5 | 6 |
5 | 6 | 7 |
x=table(["s1", "s2", "", "s4", "s5"] as col1, ["s1", "", "s3", "", "s5"] as col2)
mlastNot(X=x, window=2)
#0 | #1 |
---|---|
|
|
s2 | s1 |
s2 | s3 |
s4 | s3 |
s5 | s5 |
T = [2022.01.01, 2022.01.02, 2022.01.03, 2022.01.06, 2022.01.07, 2022.01.08, 2022.01.10, 2022.01.11]
X = 1..8
X1 = indexedSeries(T, X)
mlastNot(X=X1, window=3, k=1, minPeriods=1)
#0 | |
2022.01.01 | |
2022.01.02 | 2 |
2022.01.03 | 2 |
2022.01.06 | 4 |
2022.01.07 | 4 |
2022.01.08 | 4 |
2022.01.10 | 6 |
2022.01.11 | 7 |