
:: ::: |
access variables in a namespace |
$ @ |
component / slot extraction |
[ [[ |
indexing |
^ |
exponentiation (right to left) |
- + |
unary minus and plus |
: |
sequence operator |
%any% |
special operators (including %% and %/% ) |
* / |
multiply, divide |
+ - |
(binary) add, subtract |
< > <=>= == != |
ordering and comparison |
! |
negation |
& && |
and |
| || |
or |
~ |
as in formulae |
-> ->> |
rightwards assignment |
<- <<-< code=""> |
assignment (right to left) |
= |
assignment (right to left) |
? |
help (unary and binary) |
=
is not
necessarily an operator.) The binary operators ::
, :::
, $
and @
require
names or string constants on the right hand side, and the first two
also require them on the left.
The links in the See Also section cover most other aspects of the basic syntax.
Arithmetic
, Comparison
, Control
,
Extract
, Logic
,
NumericConstants
, Paren
,
Quotes
, Reserved
.The ‘R Language Definition’ manual.
## Logical AND ("&&") has higher precedence than OR ("||"):
TRUE || TRUE && FALSE # is the same as
TRUE || (TRUE && FALSE) # and different from
(TRUE || TRUE) && FALSE
## Special operators have higher precedence than "!" (logical NOT).
## You can use this for %in% :
! 1:10 %in% c(2, 3, 5, 7) # same as !(1:10 %in% c(2, 3, 5, 7))
## but we strongly advise to use the "!( ... )" form in this case!
## '=' has lower precedence than '<-' ... so you should not mix them
## (and '<-' is considered better style anyway):
## Consequently, this gives a ("non-catchable") error
x <- y = 5 #-> Error in (x <- y) = 5 : ....
Run the code above in your browser using DataLab