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: unary functions

$ rowFunc(args…)

Additional unary function template (released with version 2.00.10)

$ rowFunc(X)

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.

X is a matrix, array vector or columnar tuple.

Template 2: binary functions (released with version 2.00.4)

$ rowFunc(X, Y)

Parameters

X and Y are matrices/numeric vectors/array vectors of the same size.

The following binary functions accept two columnar tuples as arguments: rowWavg, rowCorr, rowCovar, rowBeta, and rowWsum, rowCumwsum

List of Functions

Other Row-Based Functions:

See also

args is a matrix:

rowRank, rowDenseRank.

args can be tuples, matrices or tables:

rowKurtosis, rowSkew

X is a matrix or an array vector, Y is a vector or an array vector:

rowAt, rowAlign

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]
../../_images/rowfunc_1.png

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]