mod(%)

Syntax

X % Y

Arguments

X and Y is a scalar/pair/vector/matrix. If X or Y is a pair/vector/matrix, the other is a scalar or a pair/vector/matrix of the same size. If X is of integer type, Y cannot be negative integer(s).

Details

mod means modulus. It returns the element-by-element remainder of X divided by Y. The modulus is always non-negative and less than Y. Y must be positive integer(s); otherwise the calculation returns a NULL value.Function mod is often used to group data. For example, [5,4,3,3,5,6]%3 is [2,1,0,0,2,0]; data can thereby be divided into three groups. When X is a negative integer, the modulus is still non-negative, for example, -10%3 is 2.

Examples

$ x=1 2 3;
$ x % 2;
[1,0,1]

$ 2 % x;
[0,0,2]

$ y=4 5 6;
$ x mod y;
[1,2,3]
$ mod(y, x);
[0,1,0]

$ m=1..6$2:3;
$ m;

#0

#1

#2

1

3

5

2

4

6

$ m mod 3;

#0

#1

#2

1

0

2

2

1

0

$ x=-1 2 3;
$ x%-5;
[,,]

$ -1%5;
4