In R, the xor() function is used to evaluate exclusive-OR between x and y argument values. Exclusive-OR or shortly XOR is a boolean logical operation. It takes two boolean input values and returns TRUE or FALSE. If input values are the same, it returns FALSE, otherwise, it returns TRUE.
X | Y | X⊕Y |
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
xor(x, y)
It takes the following argument values:
x: First logical valuey: Second logical valueIt returns exclusive-OR between argument values x and y and return the result as a logical type.
In this code snippet, we are heading to create two logical vectors and calculate xor between them:
# Creating two r vectors named x & yx <- c(FALSE, FALSE, TRUE, TRUE)y <- c(FALSE,TRUE, FALSE, TRUE)# Invoking xor() function to computer# exclusive-or between two vectors x & ycat(xor(x,y))
x variable as a logical vector.y variable as a logical vector.xor() to calculate exclusive-OR between the argument values.