Retrieve or set the row or column names of a matrix-like object.
1 2 3 4 5
a matrix-like R object, with at least two dimensions for
for created names.
a valid value for that component of
The extractor functions try to do something sensible for any
x. If the object has
the first component is used as the row names, and the second component
(if any) is used for the column names. For a data frame,
colnames eventually call
names respectively, but the latter are preferred.
FALSE, a character vector (of length
NCOL(x)) is returned in any
prefix to simple numbers, if there are no
dimnames or the corresponding component of the dimnames is
The replacement methods for arrays/matrices coerce vector and factor
value to character, but do not dispatch methods for
For a data frame,
rownames should be a
character vector of non-duplicated and non-missing names (this is
enforced), and for
colnames a character vector of (preferably)
unique syntactically-valid names. In both cases,
value will be
as.character, and setting
will convert the row names to character.
If the replacement versions are called on a matrix without any existing dimnames, they will add suitable dimnames. But constructions such as
rownames(x) <- "c"
may not work unless
x already has dimnames, since this will
create a length-3
value from the
NULL value of
1 2 3 4 5 6 7 8
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.