Skip to contents

Integer remainder of the division of the integer n by m: n mod m.

Usage

mod(n, m, ...)

# S4 method for matrix,numeric
mod(n, m)

Arguments

n

A numeric vector (preferably of integers), a matrix where each element can be reduced to integers.

m

An integer vector (positive, zero, or negative).

...

Not in use.

Value

An element of x, an Automorphism-class object.

Author

Robersy Sanchez (https://genomaths.com).

Examples

## Example 1
## Build a matrix 'n' and set a vector of integers 'm'
n <- diag(x=1, nrow = 4, ncol = 4) * c(43,125,2,112)
m <- c(64,4,4,64)

## Operation n mod m 
mod(n = n, m = m)
#>      [,1] [,2] [,3] [,4]
#> [1,]   43    0    0    0
#> [2,]    0    1    0    0
#> [3,]    0    0    2    0
#> [4,]    0    0    0   48

## Or simply:
n %% m
#>      [,1] [,2] [,3] [,4]
#> [1,]   43    0    0    0
#> [2,]    0    1    0    0
#> [3,]    0    0    2    0
#> [4,]    0    0    0   48

## Example 2
m <- matrix(c(8,2,3, 11,12,13), nrow = 2)
m
#>      [,1] [,2] [,3]
#> [1,]    8    3   12
#> [2,]    2   11   13

m %% 4
#>      [,1] [,2] [,3]
#> [1,]    0    3    0
#> [2,]    2    3    1