0% found this document useful (0 votes)
27 views3 pages

R Programming Operators Explained

Operators in R perform mathematical operations on variables and values. There are arithmetic, relational, and logical operators. Arithmetic operators include addition, subtraction, multiplication, and division. Relational operators compare elements between vectors and return boolean values.

Uploaded by

sanjayvj666
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

R Programming Operators Explained

Operators in R perform mathematical operations on variables and values. There are arithmetic, relational, and logical operators. Arithmetic operators include addition, subtraction, multiplication, and division. Relational operators compare elements between vectors and return boolean values.

Uploaded by

sanjayvj666
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Operators In R :-

An operator is a symbol that will perform various


mathematical operations on variables or on values.
Operators operate on operands and return results.

R language is rich in built-in operators and provides


following types of operators.

Types of Operators:-
We have the following types of operators in R
programming −

• Arithmetic Operators
• Relational Operators
• Logical Operators
• Assignment Operators

1. Arithmetic Operators:-

Operator Description Example

1.(+) addition Add two Ex. 5+6 , 60+90 , a+b


no.,vector,matrix
etc Ex. c(1,2,3,4)+c(5,6,7,8)

2.(-) substraction Substract two Ex. 5 - 6 , 60 - 90 , a - b


no.,vector,matrix
etc Ex. c(1,2,3,4) - c(5,6,7,8)

3.(* ) multiplication multiply two Ex. 7*9 , 20*40, a*b


no.,vector,matrix
etc Ex. c(6,7,8) * c(2,3,4)
4.(/ ) division divide two Ex. 7 / 9 , 20 / 40, a / b
no.,vector,matrix
etc Ex. c(6,7,8) / c(2,3,4)

5.( %%) modular division Moudular division of Ex. 7%%3 , 20%%40, a%%b
two
(remainder) no.,vector,matrix Ex. c(6,7,8) %% c(2,3,4)
etc

6.(%/% ) integer division Integer division of Ex. 7%/%9 , 20%/%40, a%/%b


two
Floor division no.,vector,matrix Ex. c(6,7,8) %/% c(2,3,4)
etc

2. Relational Operators:-
(comparison operator)
The relational operators supported by R language.
Each element of the first vector is compared with the
corresponding element of the second vector. The result of
comparison is a Boolean value.

Table for relational operator:-


Operator Description Example

> a <- c(2,5.5,6,9)


Checks if each element of the first vector b <- c(8,2.5,14,9)
is greater than the corresponding element print(a > b)
of the second vector.
output:-
[1] FALSE TRUE FALSE FALSE
< a <- c(2,5.5,6,9)
Checks if each element of the first vector b <- c(8,2.5,14,9)
is less than the corresponding element of print(a < b )
the second vector. output:-
[1] TRUE FALSE TRUE FALSE

== a <- c(2,5.5,6,9)
Checks if each element of the first vector b <- c(8,2.5,14,9)
is equal to the corresponding element of print(a == b)
the second vector. output:-
[1] FALSE FALSE FALSE TRUE

<= a <- c(2,5.5,6,9)


Checks if each element of the first vector b <- c(8,2.5,14,9)
is less than or equal to the corresponding print(a <= b)
element of the second vector. output:-
[1] TRUE FALSE TRUE TRUE

>= a <- c(2,5.5,6,9)


Checks if each element of the first vector
b <- c(8,2.5,14,9)
is greater than or equal to the print(a >= b)
corresponding element of the second
output:-
vector.
[1] FALSE TRUE FALSE TRUE

!= a <- c(2,5.5,6,9)
b <- c(8,2.5,14,9)
Checks if each element of the first vector print(a!= b)
is unequal to the corresponding element
of the second vector. output :-
[1] TRUE TRUE TRUE FALSE

THANK YOU

You might also like