# R Cheatsheet: Logical Operators

#Equal to

==

#Non equal to

!=

#Less than

<

#Less than or equal to

<=

#Greater than

<

#Greater than or equal to

<=

#Negation (NOT operator), or to negate a boolean expression:

!(b==c)

#AND (Conjunction)

#we can use both ‘&’ and ‘&&’ the difference between this two symbols is that the first evaluates ALL the elements of a vector, and the second only the first element of a vector. #OR (Disjunction)

#The OR operator follows a similar set of rules. The `|` version of OR evaluates OR across an entire vector, while the `||` version of OR only evaluates the first member of a vector. #Important!: The rules of precedence dictate that ALL the AND operations are evaluated first, then the OR operations are calculated later.

FALSE && 6 >= 6 || 7 >= 8 || 50 <= 49.5

#The expression from above results in FALSE, because by the rules of precedence we first evaluate FALSE && 6 >= 6  OBTAINING  a FALSE, after thaht we evaluate the OR operations resulting in FALSE.

#R has a function to evaluate is an expression is TRUE

isTRUE() #Identical is a function which evaluates if two elements are equal returning TRUE. #XOR

#The xor() function stands for exclusive OR. If one argument evaluates to TRUE and one argument evaluates to  FALSE, then this function will return TRUE, otherwise it will return FALSE.

xor(5==6, !FALSE)
 TRUE

#WHICH

#A function that returns the elements of a vector complying with a logical operation:

x<-sample(10)

WHICH(x>5)

#ANY

#Returns TRUE if at least an element of the vector evaluated is TRUE.

ANY(x>2)

#ALL

#Returns TRUE if all elements are true:

ALL(x>0) #### Acerca de martincx

Fútbol, cine, historia y literatura. Quejándome del fútbol moderno. Ojalá y escribir fuera un trabajo remunerado.