I have a general question about the or and and operators in R.
In the below example, I am assigning a value to 2 variables x and y and Im just doing some logical operations on them. But when I wrap the expression in parenthesis, the result changes... and I'm wondering why or what is the logic behind this? For example:
x = 10
y = 2
# x or y is equal to 2
>x|y == 2
[1] TRUE
But when I add parenthesis:
> (x|y) == 2
[1] FALSE
Additionally, if I just check the x:
> x|x == 2
[1] TRUE
> (x|x) == 2
[1] FALSE
Similarily for &:
> x&y == 2
[1] TRUE
> (x&y)==2
[1] FALSE
I know this might be a basic question, but the logic behind this isn't as intuitive as I originally thought! I know there are lots of resources online talking about these operators.. but none of them seem to answer this type of question directly. I was wondering what is exactly going on here?