To start, we will define matrices A and B, using matrix(). This function creates a dataset with rows and columns. Then compute addition and subtraction:
Then, using diag() we will create a diagonal matrix.
Using diag() with cbind(), which combines multiple matrices, data frames, or vectors together, we can construct a custom 5×5 matrix very simply.
Leave a Reply