Arithmetic {base} | R Documentation |
These binary operators perform arithmetic on vector objects.
x + y
x - y
x * y
x / y
x ^ y
x %% y
x %/% y
1 ^ y
and y ^ 0
are 1
, always.
x ^ y
should also give the proper “limit” result when
either argument is infinite (i.e., +- Inf
).
Objects such as arrays or time-series can be operated on this way provided they are conformable.
They return numeric vectors containing the result of the element
by element operations. The elements of shorter vectors are recycled
as necessary (with a warning
when they are recycled only
fractionally). The operators are +
for addition,
-
for subtraction *
for multiplication, /
for
division and ^
for exponentiation.
%%
indicates x mod y
and %/%
indicates integer
division. It is guaranteed that x == (x %% y) + y * ( x %/% y )
unless y == 0
where the result is NA
or
NaN
(depending on the typeof
of the arguments).
sqrt
for miscellaneous and Special
for special
mathematical functions.
Syntax
for operator precedence.
x <- -1:12
x + 1
2 * x + 3
x %% 2 #-- is periodic
x %/% 5