Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logical operators - short (relational) vs long (vector) forms

I am getting a bit confused by the use of the short and long forms of logical operators in R.

If I have the following values

A <- FALSE
B <- TRUE
X <- 3
Y <- 2

I would like to evaluate NOT(A) OR NOT(B) AND X < Y

I expect FALSE given the parameters

This is the expression I have found to evaluate this in R so it returns FALSE as I expect:

!A & X < Y || !B & X < Y

Can I eliminate the repeated X < Y comparison?

like image 651
Simon O'Hanlon Avatar asked Jan 13 '23 22:01

Simon O'Hanlon


1 Answers

Do you mean:

> (!A || !B) && X < Y
[1] FALSE

?

like image 57
NPE Avatar answered Jan 19 '23 10:01

NPE