Chapter 4 be careful

TRUE && c(TRUE, FALSE, FALSE)
## [1] TRUE

In this case, the left operand is only evaluated with the first member of the right operand (the vector). The rest of the elements in the vector aren’t evaluated at all in this expression.

TRUE | FALSE
## [1] TRUE
TRUE | c(TRUE, FALSE, FALSE)
## [1] TRUE TRUE TRUE
TRUE || c(TRUE, FALSE, FALSE)
## [1] TRUE
FALSE && 6 >= 6 || 7 >= 8 || 50 <= 49.5
## [1] FALSE
!(8 > 4) ||  5 == 5.0 && 7.8 >= 7.79
## [1] TRUE
TRUE && FALSE || 9 >= 4 && 3 < 6
## [1] TRUE
99.99 > 100 || 45 < 7.3 || 4 != 4.0
## [1] FALSE
isTRUE(6>4)
## [1] TRUE
identical('twins', 'twins')
## [1] 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
xor(T, T)
## [1] FALSE
xor(F, F)
## [1] FALSE
xor(identical(xor, 'xor'), 7 == 7.0)
## [1] TRUE
xor(4 >= 9, 8 != 8.0)
## [1] FALSE
ints <- sample(10)
ints > 5
##  [1]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE  TRUE FALSE FALSE

The which() function takes a logical vector as an argument and returns the indices of the vector that are TRUE.

which(c(TRUE, FALSE, TRUE))
## [1] 1 3
x <- ints>7

which(x)
## [1] 1 5 7

The any() function will return TRUE if one or more of the elements in the logical vector is TRUE.

any(ints<0)
## [1] FALSE

The all() function will return TRUE if every element in the logical vector is TRUE.

all(ints>0)
## [1] TRUE
any(ints == 10)
## [1] TRUE
all(c(TRUE, FALSE, TRUE))
## [1] FALSE

4.1 matrices and data frames