Matrix in R

Matrices and arrays can be described as multidimensional vectors. Like a vector, they can only contain data of a single type, but in addition to being long, they have more dimensions.

In a strict sense, matrices are a special case of an array, distinguished by specifically having two dimensions, a “length”” and a “height”. Matrices are, therefore, a rectangular-shaped structure, with rows and columns.

Because matrices are used regularly in mathematics and statistics, it is a commonly used data structure in R and one that we will focus on in this book.

Arrays, for their part, can have an arbitrary number of dimensions. They can be cubes, hypercubes and other shapes. Its use is not very common in R, although sometimes it is desirable to have n-dimensional objects to manipulate data. Because arrays have the constraint that all their data must be of the same type, no matter how many dimensions they are in, this limits their practical uses.

In general, it is preferable to use lists instead of arrays, a data structure that also has certain advantages that we will see later.

An interesting book to learn about matrix algebra it is

https://bookdown.org/jboscomendoza/r-principiantes4/matrices-y-arrays.html