Row-Based Functions
For most DolphinDB functions that are applicable to matrices or tables, the calculation is usually conducted based on columns. To calculate on rows, you can use row-based functions.
Introduction
Higher-order function byRow :
$ byRow(func, X)
General templates for row-based functions are:
Template 1
$ rowFunc(args…)
Parameters
args can be a scalar/matrix, or one or more vectors/tuples/tables or their combination. The length of vector, the number of elements of a tuple, and the number of table columns must be the same.
Note: If args is a matrix, return a vector of the same length as the number of rows of the matrix. Please note that multiple matrices are not supported in row functions.
Template 2 (released with version 2.00.4)
$ rowFunc(X, Y)
Parameters
X and Y are matrices of the same size or vectors/array vectors with the same number of rows.
List of Functions
See also
rowFunc(args…)
rowMax, rowMin, rowCount, rowSize,
rowSum, rowSum2, rowAvg, rowProd,
rowStd, rowStdp, rowVar, rowVarp,
rowFunc(X, Y)
Other Row-Based Functions:
See also
args is a matrix:
args can be vectors, tuples, matrices or tables:
Calculation Rules
To calculate on different data forms, please see the following example.
$ vec = [1,2,3]
$ vec_tuple = [[3,4,5],[4,5,6]]
$ tb = table(7 8 9 as id, 8 9 10 as code)
$ print rowSum(vec, vec_tuple, tb)
[23, 28, 33]
To calculation on a matrix:
$ m = matrix(4 2 1 3 5 8, 1 2 5 9 0 1, 3 6 3 2 1 5)
$ print rowSum(m)
[8, 10, 9, 14, 6, 14]