R – AND Logical Operator
R – AND Operator &
is used to perform logical AND operation between two boolean operands.
&
symbol is used for Logical AND Operator in R Language.
AND Operator takes two boolean values as operands and returns the logical AND of the two operands.
The syntax of AND Operator with the two boolean operands is
operand1 & operand2
Truth Table
The following truth table provides the output of AND operator for different values of operands.
operand1 | operand2 | operand1 & operand2 |
---|---|---|
TRUE | TRUE | TRUE |
TRUE | FALSE | FALSE |
FALSE | TRUE | FALSE |
FALSE | FALSE | FALSE |
AND Operation returns TRUE only if both the operands are TRUE, else it returns FALSE.
Example
In the following R program, we will take different boolean values for operands and find the result of AND operation on these operands.
example.r
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 = FALSE
FALSE & TRUE = FALSE
FALSE & FALSE = FALSE
Conclusion
Concluding this R Tutorial, we learned what R Logical AND Operator is, and the output of AND Operation for different boolean values as operands, with the help of an example program.