rownames() function in R Language is used to set the names to rows of a matrix.
Syntax:
rownames(x) <- valueParameters:
x: Matrix
value: Vector of names to be set
Example:
# R program to provide a name # to rows of a Matrix # Creating a 3X3 Matrix A = matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 9), 3, 3, byrow = TRUE) # Calling rownames() Function rownames(A) <- letters[1:3] print(A) |
chevron_right
filter_none
Output:
[, 1] [, 2] [, 3] a 1 2 3 b 4 5 6 c 7 8 9
colnames() Function
colnames() function in R Language is used to set the names to columns of a matrix.
Syntax:
colnames(x) <- valueParameters:
x: Matrix
value: Vector of names to be set
Example:
# R program to provide a name # to columns of a Matrix # Creating a 3X3 Matrix A = matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 9), 3, 3, byrow = TRUE) # Calling colnames() Function colnames(A) <- letters[1:3] print(A) |
chevron_right
filter_none
Output:
a b c
[1, ] 1 2 3
[2, ] 4 5 6
[3, ] 7 8 9
Recommended Posts:
- Binding rows and columns of a Data Frame in R - bind_rows() and bind_cols() Function
- Calculate the Sum of Matrix or Array columns in R Programming - colSums() Function
- Getting a Matrix of number of columns in R Programming - col() Function
- Scale the Columns of a Matrix in R Programming - scale() Function
- Compute the Sum of Rows of a Matrix or Array in R Programming - rowSums Function
- Getting a Matrix of number of rows in R Programming - row() Function
- Get the number of columns of an Object in R Programming - ncol() Function
- Merge Two Data Frames by common Columns in R Programming - merge() Function
- Rename Columns of a Data Frame in R Programming - rename() Function
- Choose Specific Columns of a Data Frame in R Programming - select() Function
- Combine Vectors, Matrix or Data Frames by Columns in R Language - cbind() Function
- Get the number of rows of an Object in R Programming - nrow() Function
- Combine Vectors, Matrix or Data Frames by Rows in R Language - rbind() Function
- Check if the Object is a Matrix in R Programming - is.matrix() Function
- Convert a Data Frame into a Numeric Matrix in R Programming - data.matrix() Function
- Convert an Object into a Matrix in R Programming - as.matrix() Function
- Transform the Scaled Matrix to its Original Form in R Programming - Using Matrix Computations
- Find Eigenvalues and Eigenvectors of a Matrix in R Programming - eigen() Function
- Getting the Modulus of the Determinant of a Matrix in R Programming - determinant() Function
- Return a Matrix with Lower Triangle as TRUE values in R Programming - lower.tri() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

