Logical Operators
In this lesson, we will learn the basic logical operations in R and how to use them.
We'll cover the following
What are Logical Operators?
Logical operators are used for carrying out Boolean operations like AND
, OR
etc. Such operators compile the results of multiple logical tests into a single TRUE
or FALSE
.
Following are the logical operators in R language:
Let’s dive right into the coding part:
number1 <- 10number2 <- 3number1 & number2 # element wise logical AND between number1 and number2number1 && number2 # logical AND between number1 and number2number1 | number2 # element wise logical OR between number1 and number2number1 || number2 # logical OR between number1 and number2!number1 # NOT of number1xor(number1, number2) # XOR of number1 and number2
All these statements either return TRUE
or FALSE
.