R Operator Precedence

In this tutorial you will learn about the R Operator Precedence and its application with practical example.

R Operator Precedence

Operator precedence defines the order in which given mathematical expression is evaluated. When an expression includes multiple operators then each of the single part of given expression is evaluated in a certain order following some rules defined as per operator precedence.Operator with higher precedence is evaluated first and operator with lowest precedence is evaluated at last.

R Operator Associativity

Operators with same precedence follows operator associativity defined for its operator group. In R, operators can either follow left-associative, right-associative or have no associativity. Operators with left-associative are evaluated from the left to right, operators with right-associative are evaluated from right to the left and operators with no associativity, does not follow any predefined order.

Following is R operator precedence table with their respective associativity –

Operator Precedence in R (Highest to Lowest)
Operator Description Associativity
^ Exponent Right to Left
-x, +x Unary minus, Unary plus Left to Right
%% Modulus Left to Right
*, / Multiplication, Division Left to Right
+, – Addition, Subtraction Left to Right
<, >, <=, >=, ==, != Comparisions Left to Right
! Logical NOT Left to Right
&, && Logical AND Left to Right
|, || Logical OR Left to Right
->, ->> Rightward assignment Left to Right
<-, <<- Leftward assignment Right to Left
= Leftward assignment Right to Left
Recommended:-  R Reference Class
In this tutorial we have learn about the R Operator Precedence and its application with practical example. I hope you will like this tutorial.