R: Logical Operators

Logical Operation is used for element-wise decision operations, which is based on specific operators between the operands which are then evaluated to either True or False Boolean value.

1. Element-wise Logical AND operator (&)

It returns True if both the operands are True.

Usage: a&b

2. Element-wise Logical OR operator (|)

It returns True if either of the operands is True.

Usage: a|b

3. NOT Operator (!)

It is used to negates the status of the elements of the operand.

Usage: !a

4. Logical AND Operator (&&)

It returns True if both the operands are True.

Usage: a&&b

5. Logical OR Operator (||)

It returns True if either of the operands is True.

Usage: a||b

Examples:

> list_1<-c(1,2,3)
> list_2<-c(2,3,4)
> print(list_1&list_2)
> print(list_1|list_2)
> print(!list_1)
> print(list_1&&list_2)
> print(list_1||list_2)

Output:

[1] TRUE TRUE TRUE 
[1] TRUE TRUE TRUE 
[1] FALSE FALSE FALSE 
[1] TRUE 
[1] TRUE