| row/colnames {base} | R Documentation |
Row and Column Names
Description
Retrieve or set the row or column names of a matrix-like object.
Usage
rownames(x, do.NULL = TRUE, prefix = "row")
rownames(x) <- value
colnames(x, do.NULL = TRUE, prefix = "col")
colnames(x) <- value
Arguments
x |
a matrix-like R object, with at least two dimensions for
|
do.NULL |
logical. Should this create names if they are
|
prefix |
for created names. |
value |
a valid value for that component of
|
Details
The extractor functions try to do something sensible for any
matrix-like object x. If the object has dimnames
the first component is used as the row names, and the second component
(if any) is used for the col names. For a data frame, rownames
and colnames are equivalent to row.names and
names respectively.
If do.NULL is FALSE, a character vector (of length
NROW(x) or NCOL(x)) is returned in any
case, prepending prefix to simple numbers, if there are no
dimnames or the corresponding component of the dimnames is NULL.
For a data frame, value for rownames should be a
character vector of unique names, and for colnames a character
vector of unique syntactically-valid names. (Note: uniqueness and
validity are not enforced.)
See Also
dimnames,
case.names,
variable.names.
Examples
m0 <- matrix(NA, 4, 0)
rownames(m0)
m2 <- cbind(1,1:4)
colnames(m2, do.NULL = FALSE)
colnames(m2) <- c("x","Y")
rownames(m2) <- rownames(m2, do.NULL = FALSE, prefix = "Obs.")
m2