mfirstNot
Syntax
mfirstNot(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 first element of X that is not NULL in a sliding window.
-
If k is specified, return the first 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 vector.
Examples
mfirstNot(NULL 2 NULL 4 5, window=2)
// output: [,2,2,4,4]
x = matrix(1..5,2..6,3..7)
mfirstNot(X=x, window=3, k=1, minPeriods=2)
#0 | #1 | #2 |
---|---|---|
|
|
|
2 | 2 | 3 |
2 | 2 | 3 |
2 | 3 | 4 |
3 | 4 | 5 |
x=table(["s1", "s2", "", "s4", "s5"] as col1, ["s1", "", "s3", "", "s5"] as col2)
mfirstNot(X=x, window=2)
#0 | #1 |
---|---|
|
|
s1 | s1 |
s2 | s3 |
s4 | s3 |
s4 | 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)
mfirstNot(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 |