ArgMin and ArgMax
ArgMax(r, i), ArgMin(r, i)
ArgMax(r, i) returns the value of index i corresponding to the largest value from array «r», which must be indexed by «i». More specifically, it returns a value, ix where r[i = ix] = Max(r, i)
. If there are ties, i.e. «r» has two or more values that are equal largest, it returns the value nearest the end of «i». Similarly, ArgMin(r, i) returns the value of «i» for which «r» is smallest.
- ArgMin(R: vector[I]; I: ... optional IndexType; position: optional boolean)
- ArgMax(R: vector[I]; I: ... optional IndexType; position: optional boolean)
Use with multiple indexes
If array «r» has an index or indexes in addition to «i», ArgMax(r, i) and ArgMin(r, i) return an array indexed by those other indexes, but not by «i». For example, if «r» is indexed by «i» and j, it will return the value of «i» for which «r» is largest (or smallest) for each value of j.
If you want to find the smallest or largest value of x over more than one index, you can list all those indexes: e.g.
ArgMax(X, I: Mpg, Car_type)
It will then return an array dimensioned by a local index .Dim
and any indexes of X
that you did not list as parameters. Index .Dim
will contain the names of the indexes given as parameters, Mpg
and Car_type
, in this case. The result will contain the values of Index Mpg
and Car_type
for which X
is maximum (or minimum).
Positional usage
By default, ArgMax and ArgMin return a value of the index. If you specify optional parameter «position» as True
, they return the position of the value in the index for which x is maximum (minumum) -- a number. For example:
ArgMax(R: Profit, I: UnitPrice, Position: true)
This helps avoid ambiguity when the index contains duplicate values.
Enable comment auto-refresher