mod | R Documentation |
Modulo operator.
mod(n, m) modq(a, b, k)
n |
numeric vector (preferably of integers) |
m |
integer vector (positive, zero, or negative) |
a,b |
whole numbers (scalars) |
k |
integer greater than 1 |
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
.
modq(a, b, k)
is the modulo operator for rational numbers and
returns a/b mod k
. b
and k
must be coprime,
otherwise NA
is returned.
a numeric (integer) value or vector/matrix, resp. an integer number
The following relation is fulfilled (for m != 0
):
mod(n, m) = n - m * floor(n/m)
rem
, div
mod(c(-5:5), 5) mod(c(-5:5), -5) mod(0, 1) #=> 0 mod(1, 0) #=> 1 modq(5, 66, 5) # 0 (Bernoulli 10) modq(5, 66, 7) # 4 modq(5, 66, 13) # 5 modq(5, 66, 25) # 5 modq(5, 66, 35) # 25 modq(-1, 30, 7) # 3 (Bernoulli 8) modq( 1, -30, 7) # 3 # Warning messages: # modq(5, 66, 77) : Arguments 'b' and 'm' must be coprime. # Error messages # modq(5, 66, 1) : Argument 'm' mustbe a natural number > 1. # modq(5, 66, 1.5) : All arguments of 'modq' must be integers. # modq(5, 66, c(5, 7)) : Function 'modq' is *not* vectorized.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.