OR in R

I became incredibly confused over logical expressions in R. The following command gives me the expected result, since 1 is equal to 1 or equal to 2:

> 1 == (1 | 2) [1] TRUE 

But then again I get:

 3 == (3 | 4) [1] FALSE 

If anyone could tell what is happening here, I would be very grateful!

+6
source share
1 answer

Please read the comments below your question for an explanation. I assume you really want to do:

 1 == 1 | 1 == 2 

This is TRUE because the first test is TRUE .

 3 == 3 & 3 == 4 

This is FALSE because the second test is FALSE and & requires both (or all) of the tests to be TRUE .

0
source

All Articles