Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Boolean (logical) operations on vectors

a = c(TRUE, TRUE, FALSE, FALSE)
b = c(TRUE, FALSE, TRUE, FALSE)
sum(a)
sum(b)  # number of TRUE items

a & b
a | b
! a
a = c(TRUE, TRUE, FALSE, TRUE)
b = c(TRUE, FALSE, TRUE, FALSE)
c = c(TRUE, FALSE, FALSE, TRUE)

a & b
a | b
! a

# operator precedence
# the use of parentheses

a & (b | c)