isPeak
Syntax
isPeak(X, [strict=true])
Arguments
X is a numeric vector/matrix/table.
strict is a Boolean value. The default value is true.
If strict = true, the adjacent elements cannot be NULL and are strictly smaller than the element;
If strict = false, the adjacent elements cannot be NULL and are no greater than the element.
Details
If X is a vector, check if each element in X is the peak.
If X is a matrix, perform the aforementioned calculations on each column and return a matrix of the same size as X.
If X is a table, only the numeric columns are involved in the calculations.
Examples
$ v = [1, 2.2, 2.2, 2.2, 2.3, 1, 1.2]
$ isPeak(v)
[0,0,0,0,1,0,0]
$ v = [1, 2.2, 2.2, 2.2, 1.6, 1, 1.2]
$ isPeak(v)
[0,0,0,0,0,0,0]
$ isPeak(v, false)
[0,1,1,1,0,0,0]
// Perform the calculations on each column in a matrix
$ m = matrix(3.3 2.8 5.6 NULL 2.5 1.2, 4.5 3.5 4.6 2.8 3.9 NULL)
$ isPeak(m)
#0 |
#1 |
---|---|
0 |
0 |
0 |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
0 |
// Perform the calculations on the numeric columns in a table
$ t = table(`01`01`00`01`02`00 as id, 2022.01.01 + 1..6 as date, 388.3 390.6 390.8 390.6 390.3 391.5 as price)
$ isPeak(t)
id |
date |
price |
---|---|---|
01 |
2022.01.02 |
0 |
01 |
2022.01.03 |
0 |
00 |
2022.01.04 |
1 |
01 |
2022.01.05 |
0 |
02 |
2022.01.06 |
0 |
00 |
2022.01.07 |
0 |
Related function: isValley