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)
  • Syntax template for unary row-based functions:

    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.

  • Syntax template for binary row-based functions:

    rowFunc(X, Y)

    Parameters:

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

    .

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)
// output
[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)
// output
[8, 10, 9, 14, 6, 14]