Why TRUE == “TRUE” is TRUE in R?

According to the help file ?`==` : If the two arguments are atomic vectors of different types, one is coerced to the type of the other, the (decreasing) order of precedence being character, complex, numeric, integer, logical and raw. So TRUE is coerced to “TRUE” (i. e. as.character(TRUE)), hence the equality. The equivalent of an … Read more

How do I test if a variable does not equal either of two values?

Think of ! (negation operator) as “not”, || (boolean-or operator) as “or” and && (boolean-and operator) as “and”. See Operators and Operator Precedence. Thus: if(!(a || b)) { // means neither a nor b } However, using De Morgan’s Law, it could be written as: if(!a && !b) { // is not a and is … Read more