5. Vectors & Matrices

Element-wise ops, summary stats, matrix algebra

Vectors

x <- c(1, 3, 5, 7)
y <- c(2, 4, 6, 8)
x + y
sum(x); mean(x); sd(x)

Matrices

M <- matrix(1:9, nrow = 3, byrow = TRUE)
M
t(M)              # transpose
M %*% t(M)        # matrix multiply

Try it