max
Syntax
max(X)
Arguments
X is a scalar/vector/matrix.
Y is an optional parameter, which can be a scalar, a vector of the same length as X or a matrix.
Details
For one input:
If X is a vector, return the maximum in X.
If X is a matrix, return a vector composed of the maximum in each column of X.
As with all aggregate functions, NULL values are not included in the calculation.
For two inputs:
If Y is a scalar, compare it with each element in X, replace the element in X with the larger value.
If Y and X are of the same type and length, compare the corresponding elements of them and return a vector containing each larger value.
Note: Before version 1.30.20/2.00.8, the function max
compares the values of temporal types by converting them into LONG values;
Since version 1.30.20/2.00.8, DolphinDB has changed the handling of temporal types:
If X and Y are temporal scalars with different levels of time granularity, the coarser-grained value is converted to the finer granularity for comparison.
If X and/or Y is a vector, matrix, or table, the compared elements must be of the same temporal type.
Examples
$ max(1 2 3);
3
$ max(7.8 9 5.4);
9
$ (5 8 2 7).max();
8
$ m=matrix(1 2 3, 4 5 6);
$ m;
#0 |
#1 |
---|---|
1 |
4 |
2 |
5 |
3 |
6 |
$ max(m);
[3,6]
$ max(m);
[3,6]
$ max(1 2 3, 2)
2 2 3
$ n = matrix(1 1 1, 5 5 5)
$ n;
#0 |
#1 |
---|---|
1 |
5 |
1 |
5 |
1 |
5 |
$ max(m, n);
#0 |
#1 |
---|---|
1 |
5 |
2 |
5 |
3 |
6 |
Related function: mmax