Search⌘ K

Logical Operators

Explore logical operators in R to combine multiple Boolean conditions into TRUE or FALSE outcomes. This lesson helps you understand and apply operators like AND, OR, and NOT to write logical expressions for data analysis.

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:

Logical operators in R language
Logical operators in R language

Let’s dive right into the coding part:

R
number1 <- 10
number2 <- 3
number1 & number2 # element wise logical AND between number1 and number2
number1 && number2 # logical AND between number1 and number2
number1 | number2 # element wise logical OR between number1 and number2
number1 || number2 # logical OR between number1 and number2
!number1 # NOT of number1
xor(number1, number2) # XOR of number1 and number2

All these statements either return TRUE or FALSE.