mod {numbers} | R Documentation |
Modulo operator.
mod(n, m)
n |
numeric vector (preferably of integers) |
m |
integer vector (positive, zero, or negative) |
mod(n, m)
is the modulo operator and returns n\,mod\,m.
mod(n, 0)
is n
, and the result always has the same sign
as m
.
a numeric (integer) value or vector/matrix
The following relation is fulfilled (for m != 0
):
mod(n, m) = n - m * floor(n/m)
mod(c(-5:5), 5) mod(c(-5:5), -5) mod(0, 1) #=> 0 mod(1, 0) #=> 1