Creating a matrix and accessing its properties
A matrix is a two-dimensional arrangement of vectors of the same type. Like vectors in R, the matrix is restricted to one data type. In this recipe, you will learn how to create a matrix, how to access its elements, and understand a few notes on matrix operations.
Getting ready
To get started with this recipe, you must have R installed on your computer. You also need to understand the structure of a matrix and various operations. There is no library required for this recipe, but if you are interested in advanced matrix algebra, then you might consider the See also section of this recipe. A matrix is considered as a two-dimensional grid where each cell is represented by a row and column index and the value of the cell is the entries of the matrix. The cell may contain logical, numeric, or character elements.
How to do it…
There are several ways to create a matrix, but the most convenient way to create a matrix is through the use of the matrix()
function...