Naming matrix rows and columns
Assign name attributes to rows of a matrix:
rownames(matrix)
Assign name attributes to columns of a matrix:
colnames(matrix)
Matrix operations
Finding Matrix Dimensions
Combining Vectors or Matrices by Row
Combining Vectors or Matrices by Column
Indexing matrices by element
Extract a single element:
Extract multiple elements:
Indexing matrices by rows and columns
Extract a single row:
Extract a single column:
Extract multiple rows or columns:
Rank values of a vector
Rank values of a vector:
Rank values of a matrix:
Calculate the sum of values in a vector or a matrix
Sum of values in a vector:
Sum of values in a matrix:
Concepts
Like vectors, matrices only contain one data type. Unlike vectors, they are two-dimensional.
When adding a vector to a matrix, it’s good practice to make sure the new vector is the same length as the number of rows or columns in the matrix.