byRow

Syntax

byRow(func, X)

Arguments

func is either a vector function (both input and output are vectors of equal length) or an aggregate function.

X :guilabel:’X’ is a matrix/array vector. The func is executed over each row of X.

Each line data of X is executed by the func.

Details

Apply the specified function to each row of a matrix.

Examples

```\$ m=matrix(1 1, 2 3, 2 1);
\$ m;
```

col1

col2

col3

1

2

2

1

3

1

```\$ byRow(add{10 20 30},m);
```

col1

col2

col3

11

22

32

11

23

31

```\$ byRow(mode,m);
[2,1]
```
```\$ b=array(DOUBLE[], 0, 10).append!([11.8 21.2 23.9, 83.3 90.2 78.2 86.5, 10.1 12.4 16.8])
[111.8 121.2 123.9,183.3 190.2 178.2 86.5,110.1 112.4 116.8]
\$ byRow(imax,b)
[2,1,2]
```

Many functions, such as imax, imin, etc., can only process data in each column of the matrix. The function byRow is recommended if you need to process the data in each row of the table. Take an example, to take the maximum index of each row of data in table t, you should transfer the table to matrix, then apply the funtion imax to each row by the function byRow.

```\$ qty1 = 2200 1900 2100 3200 6800 5400 1300 2500 8800
\$ qty2 = 2100 1800  6800 5400 1300 2400 8500 4100 3200
\$ qty3 = 7800 5400 5300 2500 1800 2200 3900 3100 1200
\$ qty4 = 3200 2800 6400 8300 2300 3800 2900 1600 2900
\$ t = table(qty1, qty2, qty3, qty4);

\$ byRow(imax, matrix(t))
```