0% found this document useful (0 votes)
168 views

Operator

The presentation discusses various types of operators in R programming language including arithmetic, relational, logical, assignment, and miscellaneous operators. Arithmetic operators cover addition, subtraction, multiplication, division and modulus. Relational operators compare values and return true or false. Logical operators combine conditions using AND, OR and NOT. Assignment operators assign values to objects. Miscellaneous operators include mixed operations.

Uploaded by

Aanchal Gangyan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
168 views

Operator

The presentation discusses various types of operators in R programming language including arithmetic, relational, logical, assignment, and miscellaneous operators. Arithmetic operators cover addition, subtraction, multiplication, division and modulus. Relational operators compare values and return true or false. Logical operators combine conditions using AND, OR and NOT. Assignment operators assign values to objects. Miscellaneous operators include mixed operations.

Uploaded by

Aanchal Gangyan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Presentation

Himanshi Swami
Overview

Topic:  Introduction to R
Types of  Types of Operators in R
Operators in  Arithmetic Operators
 Relational Operators
R  Logical Operators
 Assignment Operators
 Miscellaneous Operators

9/3/20XX Presentation Title 2


Introduction to R

The R programming language is an open source


scripting language for predictive analytics and data
visualization. The R programming language
includes functions that support linear modeling, non-
linear modeling, classical statistics, classifications,
clustering and more. The appeal of the R language
had gradually spread out of academia into business
settings, as many data analytics who trained on R in
college prefer using it rather than pick up new tool
with which they are inexperienced.

9/3/20XX Presentation Title 3


What are R-operators?
Operators are the symbols directing the compiler to
perform various kinds of operations between the operands.
Operators simulate the various mathematical, logical, and
decision operations performed on a set of Complex
Numbers, Integers, and Numerical as input operands.
R support majorly four kinds of binary operators between
a set of operands. R language is rich in bult-in operators.

9/3/20XX Presentation Title 4


TYPES OF R-OPERATORS
Arithmetic Operators
Logical Operators
Relational Operators
Assignment Operators
Miscellaneous Operators

9/3/20XX Presentation Title 5


ARITHEMETIC
OPERATORS
ARITHMETIC OPERATORS
• Arithmetic operations simulate various math operations, like addition,
subtraction, multiplication, division, and modulo using the specified
operator between operands, which may be either scalar values,
complex numbers, or vectors.
• The operations are performed element-wise at the corresponding
positions of the vectors.
• All these R arithmetic operators are binary operators, which means
they operate on two operands.

9/3/20XX Presentation Title 7


Input : a <- 6 b <- 8.4 print (a-b) Output : -2.4

 Addition Operator(+):

The value at the corresponding positions of both the operands are added.

Input : a<- c(1, 0.1)


b<- c(2.33, 4)
print (a+b)
Output : 3.33 4.10

 Subtraction Operator(-):

The second operand values are subtracted from the first.

Input : a<- 6
b<- 8.4
print(a-b)
Output : -2.4
9/3/20XX Presentation Title 8
 Multiplication Operator(*)
The multiplication of corresponding elements of vectors and Integers are multiplied with
the use of ‘*’ operator.

Input : B= matrix(c(4,6i), nrow=1,ncol=2)


C= matrix(c(2,2i), nrow=1,ncol=2
Print(B*C)
Output : 8+0i -1260i
The element at corresponding positions of matrices are multiplied.

 Division Operator(/)

The first operand is divided by the second operand with the use of ‘/’ operator

Input : a<-1
b<-0
Output ; -Inf

9/3/20XX Presentation Title 9


S.No Operators Operation
1. + Addition
2. - Subtraction
3. * Multiplication
4. / Division
5. %/% Integer Division- Same as
Division, but it return the
integer value by flooring the
extra decimal

6. ^ Exponent- It returns the Power


of One variable against the
other
7. %% Modulus- It returns remainder
after the division

9/3/20XX Presentation Title 10


9/3/20XX Presentation Title 11
RELATIONAL
OPERATORS
RELATIONAL OPERATORS
• A relational operator is a symbol which defines some kind of relation
between two entities.
• These include numeric equalities and inequalities.
• A relational operator compares each element of first vector with the
corresponding element of the second vector.
• The result of the comparison will be a Boolean Value.
• There are following relational operators which are supported by R:

9/3/20XX Presentation Title 13


S.No Operator Description

1. > This operator will return TRUE when every element in the first vector is
greater than the corresponding element of the second vector.

2. < This operator will return TRUE when every element in the first vector is less
then the corresponding element of the second vector.

3. <= This operator will return TRUE when every element I n the first vector is
less than or equal to the corresponding element of another vector.

4. >= This operator will return TRUE when every element in the first vector is
greater than or equal to the corresponding element of another vector.

5. == The operator will return TRUE when every element in the first vector is
equal to the corresponding element of the second vector.
6. != This operator will return TRUE when every element in the first vector is not
equal to the Corresponding element of the second vector.
9/3/20XX Presentation Title 14
9/3/20XX Presentation Title 15
LOGICAL
OPERATORS
LOGICAL OPERATORS
• Logical operations simulate element-wise decision operations, based
on the specified operator between the operands, which are then
evaluated to either TRUE or FALSE Boolean value.
• Any non zero integer value is considered as TRUE value, be it
complex or real number.
• The logical operators in R programming are used to combine two or
more conditions, and perform the logical operations using &(Logical
AND), |(Logical OR) and !(Logical NOT).

9/3/20XX Presentation Title 17


S.No Operators Name Description

1. & logical AND It returns true when both conditions are


true

2. && logical AND Same as the above but, it works on


single element

3. | logical OR It return true when at-least one of the


condition is true

4. || logical OR Same as logical OR but, it works on


single element

5. ! Logical NOT If the condition is true, logical NOT


operator returns as false

9/3/20XX Presentation Title 18


9/3/20XX Presentation Title 19
ASSIGNMENT
OPERATORS
ASSIGNMENT OPERATORS
• Assignment operators are used to assign values to various data objects
in R.
• The objects may be integers, vectors, or functions.
• These values are then stores by the assigned variables names.
• There are two kind of assignment operators: Left and Right.

9/3/20XX Presentation Title 21


 Left Assignment (<- or<<-or=) :
Assign a value to a vector.

Input : vec1 = c(“ab”, TRUE)


print (vec1)
Output : “ab” “TRUE”

 Right Assignment(-> or->>) :


Assigns value to a vector.

Input : c(“ab”, TRUE) ->>vec1


print(vec1)
Output : “ab” “TRUE”

9/3/20XX Presentation Title 22


9/3/20XX Presentation Title 23
MISCELLANEO
US
OPERATORS
Miscellaneous Operators
These are the mixed operators that simulate the printing of sequences
and assignment of vectors, either left or right-handed.
These R programming operators are used for special cases and are not
for general mathematical or logical computation.

9/3/20XX Presentation Title 25


 %in% Operator :
Checks if an element belongs to a list and returns a Boolean value TRUE if the value is
present else FALSE.

Input : val <-0.1


list1<-c(TRUE, 0.1, “apple”)
print (val %in =% list1)
Output : TRUE

Checks for the vale 0.1 in the specified list. It exists, therefore, prints TRUE.

 Colon Operator(:) :
Prints a list of elements starting with the element before the color to the element after it.

Input : print(1:5)
Output : 1 2 3 4 5

Prints a sequence of the numbers from 1 to 5.


9/3/20XX Presentation Title 26
 %*% Operator :
This operator is used to multiply a matrix with its transpose. Transpose of the matrix is obtained by interchanging the
rows to columns and columns to rows. The number of columns of first matrix must be equal to number of rows of
second matrix. Multiplication of the matrix A with its transpose, B, produce a square matrix.

Input : mat= matrix(c(1,2,3,4,5,6),nrow=2,ncol=3)


print(mat)
print(t(mat))
pro=mat%*% t(mat)
print(pro)
Output : [,1] [,2] [,3] #original matrix of order2x3
[1,] 1 2 3
[2,] 2 4 6

[,1] [,2] #transposed matrix of order 3x2


[1,] 1 2
[2,] 3 4
[3,] 5 6

[,1] [,2] #product matrix of order2x2


[1,] 35 44
[2,] 44 56
9/3/20XX Presentation Title 27
9/3/20XX Presentation Title 28
Thank you

9/3/20XX Presentation Title 29

You might also like