R – OR Logical Operator

R – OR Operator | is used to perform logical OR operation between two boolean operands.

| symbol is used for Logical OR Operator in R Language.

OR Operator | takes two boolean values as operands and returns the logical OR of the two operands.

The syntax of OR Operator with the two boolean operands is

</>
Copy
operand1 | operand2

Truth Table

The following truth table provides the output of OR operator for different values of operands.

operand1operand2operand1 | operand2
TRUETRUETRUE
TRUEFALSETRUE
FALSETRUETRUE
FALSEFALSEFALSE

OR Operation returns TRUE if any of the operands is TRUE, else it returns FALSE.

Example

In the following R program, we will take different boolean values for operands and find the result of OR operation on these operands.

example.r

</>
Copy
x <- TRUE
y <- TRUE
result <- x | y
cat(x, " | ", y, " = ", result, "\n")

x <- TRUE
y <- FALSE
result <- x | y
cat(x, " | ", y, " = ", result, "\n")

x <- FALSE
y <- TRUE
result <- x | y
cat(x, " | ", y, " = ", result, "\n")

x <- FALSE
y <- FALSE
result <- x | y
cat(x, " | ", y, " = ", result, "\n")

Output

tutorialkart$ Rscript example.r
TRUE  |  TRUE  =  TRUE 
TRUE  |  FALSE  =  TRUE 
FALSE  |  TRUE  =  TRUE 
FALSE  |  FALSE  =  FALSE 

Conclusion

Concluding this R Tutorial, we learned what R Logical OR Operator is, and the output of OR Operation for different boolean values as operands, with the help of an example program.