mode
Syntax
mode(X)
Details
If X is a vector, calculate the most frequently occurring value in X.
If X is a matrix/table, calculate the most frequently occurring value in each column of X and return a vector/table.
This function counts the occurrences of unique values (keys) in X using a hash table. If there are multiple keys with the highest count, the function returns the first key in the hash table. Note that the hash algorithm used by this function varies for different data types, so the output results may differ.
As with all aggregate functions, null values are not included in the calculation.
DolphinDB mode and scipy.stats.mode have similar
functionality, but differ in several aspects:
- DolphinDB supports a single-argument form
mode(x)for directly computing the mode of a vector/matrix/table, whereas SciPy’sscipy.stats.modesupports multidimensional arrays and allows specifying the computation dimension via the axis parameter. - DolphinDB
modereturns only the mode value and does not provide frequency information, while SciPy’smodereturns a structured resultModeResult(mode, count), including both the mode and its occurrence count. - In the case of multiple modes, DolphinDB returns the first key in the hash
table, whereas SciPy’s
modeby default returns the smallest mode value. - In DolphinDB, null values are excluded from the computation, while SciPy’s
modeignores or handles NaN values depending on parameters (e.g., nan_policy).
Parameters
X is a scalar/vector/matrix/table.
Returns
-
Returns an INT scalar when X is a scalar or vector.
-
Returns an INT vector when Xis a matrix.
-
Returns a table when X is a table.
