2.1 About Matrices
First let’s talk about matrices in the mathematical sense of the word. A matrix is a rectangular array of elements. More formally, a matrix is a mathematical object whose structure is a rectangular array of entries.
Typically, we consider the elements of a matrix to be numbers. Although you can certainly generalize the contents of a matrix and think about them as any type of symbols, not necessarily numbers. This is perhaps a common way to conceive a generic matrix from a more computational-oriented perspective.
From example, an R matrix may be numeric, but you can also have matrices containing logical values (TRUE
or FALSE
), or even a matrix made up of characters.
# numeric matrix
A <- matrix(1:12, nrow = 4, ncol = 3)
A
[,1] [,2] [,3]
[1,] 1 5 9
[2,] 2 6 10
[3,] 3 7 11
[4,] 4 8 12