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

Sum of values in vectors

y = c(2, 7, 3)
sum(y)       # 12

sum(TRUE)    # 1
sum(FALSE)   # 0

the_truth = c(TRUE, FALSE, TRUE, TRUE, FALSE)
sum(the_truth)    # 3