[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  dimnames: Dimnames of an Object

##  Description

Retrieve or set the dimnames of an object.

##  Usage

    
    
    dimnames(x)
    dimnames(x) <- value
    
    provideDimnames(x, sep = "", base = list(LETTERS), unique = TRUE)

##  Arguments

x

an  R  object, for example a matrix, array or data frame.

value

a possible value for ` dimnames(x) ` : see the ‘Value’ section.

sep

a character string, used to separate ` base ` symbols and digits in the
constructed dimnames.

base

a non-empty ` [ list ](/link/list?package=base&version=3.6.2) ` of character
vectors. The list components are used in turn (and recycled when needed) to
construct replacements for empty dimnames components. See also the examples.

unique

logical indicating that the dimnames constructed are unique within each
dimension in the sense of ` [ make.unique
](/link/make.unique?package=base&version=3.6.2) ` .

##  Value

The dimnames of a matrix or array can be ` NULL ` (which is not stored) or a
list of the same length as ` dim(x) ` . If a list, its components are either `
NULL ` or a character vector with positive length of the appropriate dimension
of ` x ` . The list can have names. It is possible that all components are `
NULL ` : such dimnames may get converted to ` NULL ` .

For the ` "data.frame" ` method both dimnames are character vectors, and the
rownames must contain no duplicates nor missing values.

` provideDimnames(x) ` returns ` x ` , with “ ` NULL ` \- free” ` dimnames ` ,
i.e.each component a character vector of correct length.

##  Details

The functions ` dimnames ` and ` dimnames<- ` are generic.

For an ` [ array ](/link/array?package=base&version=3.6.2) ` (and hence in
particular, for a ` [ matrix ](/link/matrix?package=base&version=3.6.2) ` ),
they retrieve or set the ` dimnames ` attribute (see [ attributes
](/link/attributes?package=base&version=3.6.2) ) of the object. A list ` value
` can have names, and these will be used to label the dimensions of the array
where appropriate.

The replacement method for arrays/matrices coerces vector and factor elements
of ` value ` to character, but does not dispatch methods for ` as.character `
. It coerces zero-length elements to ` NULL ` , and a zero-length list to `
NULL ` . If ` value ` is a list shorter than the number of dimensions, it is
extended with ` NULL ` s to the needed length.

Both have methods for data frames. The dimnames of a data frame are its ` [
row.names ](/link/row.names?package=base&version=3.6.2) ` and its ` [ names
](/link/names?package=base&version=3.6.2) ` . For the replacement method each
component of ` value ` will be coerced by ` [ as.character
](/link/as.character?package=base&version=3.6.2) ` .

For a 1D matrix the ` [ names ](/link/names?package=base&version=3.6.2) ` are
the same thing as the (only) component of the ` dimnames ` .

Both are [ primitive ](/link/primitive?package=base&version=3.6.2) functions.

` provideDimnames(x) ` provides ` dimnames ` where “missing”, such that its
result has ` [ character ](/link/character?package=base&version=3.6.2) `
dimnames for each component. If ` unique ` is true as by default, they are
unique within each component via ` [ make.unique
](/link/make.unique?package=base&version=3.6.2) (*, sep=sep) ` .

##  References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_ .
Wadsworth & Brooks/Cole.

##  See Also

` [ rownames ](/link/rownames?package=base&version=3.6.2) ` , ` [ colnames
](/link/colnames?package=base&version=3.6.2) ` ; ` [ array
](/link/array?package=base&version=3.6.2) ` , ` [ matrix
](/link/matrix?package=base&version=3.6.2) ` , ` [ data.frame
](/link/data.frame?package=base&version=3.6.2) ` .

##  Examples

[ Run this code
](https://app.datacamp.com/workspac