HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Operators are used to perform operations on variables and values
Operators are used to perform operations on variables and values.
In the example below, we use the +
operator to add together two values:
10 + 5
R divides the operators in the following groups:
Arithmetic operators are used with numeric values to perform common mathematical operations:
Operator | Name | Example | Try it |
---|---|---|---|
+ | Addition | x + y | Try it » |
- | Subtraction | x - y | Try it » |
* | Multiplication | x * y | Try it » |
/ | Division | x / y | Try it » |
^ | Exponent | x ^ y | Try it » |
%% | Modulus (Remainder from division) | x %% y | Try it » |
%/% | Integer Division | x%/%y | Try it » |
Assignment operators are used to assign values to variables:
my_var <- 3
my_var <<- 3
3 -> my_var
3 ->>
my_var
my_var # print my_var
Note: <<-
is a global
assigner. You will learn more about this in the Global Variable chapter.
It is also possible to turn the direction of the assignment operator.
x <- 3 is equal to 3 -> x
Comparison operators are used to compare two values:
Operator | Name | Example | Try it |
---|---|---|---|
== | Equal | x == y | Try it » |
!= | Not equal | x != y | Try it » |
> | Greater than | x > y | Try it » |
< | Less than | x < y | Try it » |
>= | Greater than or equal to | x >= y | Try it » |
<= | Less than or equal to | x <= y | Try it » |
Logical operators are used to combine conditional statements:
Operator | Description |
---|---|
& | Element-wise Logical AND operator. It returns TRUE if both elements are TRUE |
&& | Logical AND operator - Returns TRUE if both statements are TRUE |
| | Elementwise- Logical OR operator. It returns TRUE if one of the statement is TRUE |
|| | Logical OR operator. It returns TRUE if one of the statement is TRUE. |
! | Logical NOT - returns FALSE if statement is TRUE |
Miscellaneous operators are used to manipulate data:
Operator | Description | Example |
---|---|---|
: | Creates a series of numbers in a sequence | x <- 1:10 |
%in% | Find out if an element belongs to a vector | x %in% y |
%*% | Matrix Multiplication | x <- Matrix1 %*% Matrix2 |
Note: You will learn more about Matrix multiplication and matrices in a later chapter.