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

I am a little confused about using 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 found to evaluate this in R , so it returns FALSE as I expect:

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

Is it possible to eliminate the repeated comparison X < Y ?

+4
source share
3 answers

Do you mean:

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

?

+5
source

short form gives you a vector.
long form gives you one meaning. compare:

  x <- c(TRUE, TRUE, FALSE) y <- c(TRUE, FALSE, FALSE) X && Y X & y x || y x | y 
+2
source

Another possibility:

 !(A * B) && X < Y 
+1
source

Source: https://habr.com/ru/post/1469285/


All Articles