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:


#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



#Identical is a function which evaluates if two elements are equal returning TRUE.



#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)
[1] TRUE


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




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



#Returns TRUE if all elements are true:


About martincx

Fútbol, cine, historia y literatura. Quejándome del fútbol moderno. Bienvenido a mi morada. Entre libremente, por su propia voluntad, y deje parte de la felicidad que trae.

Este blog se enriquece con los comentarios, deja acá tu impresión.

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Salir /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Salir /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Salir /  Cambiar )

Conectando a %s

A %d blogueros les gusta esto: