The dimnames()
function in R is used to retrieve or set the dimnames
of an object.
dimnames(x)dimnames(x) <- value
# creating a matrix objectmymatrix <- matrix(c("apple","banana","cherry","mango","pineapple","lemon"), nrow = 3, ncol = 2)# setting the name of rows and columnsdimnames(mymatrix) <- list( Rows = c('1', '2', '3'),Cols = c('col1', 'col2'))# printing the matrix objectmymatrix
mymatrix
with 3 rows and 2 columns using the matrix()
function.dimnames()
function to set the names of both the rows and columns of the matrix mymatrix
.mymatrix
.