Operators
These are the operators supported by R.
Contents
Description
Most operators work as expected. Some are spelled in unexpected ways, though.
%/% for floored division
%% for modulo
If both arguments to an operator are vectors, element-wise operations are performed.
R does not support a transposition operator. Instead use the 'transposition' function.
A_t = t(A)
Note that this gives the non-conjugate transpose. To get the Hermitian transpose, try Conj(t(A)).
For matrix multiplication, use %*%.
R does not support a matrix division operator. Instead use the solve function.
To evaluate a left division problem, as in Ax = b, try x <- solve(A, b).
to evaluate a right division problem, as in xA = b, try x <- t(solve(t(A), t(b))).
& and | are vectorized operators that return logical vectors. && and || are the more familiar logic operators, i.e. they evaluate to TRUE or FALSE and feature short-circuiting. Note that R considers very few things to be 'falsy':
NA
NULL
- an empty string
- an empty vector
a vector containing only NA values
