| row+colnames | R Documentation |
Retrieve or set the row or column names of a matrix-like object.
rownames(x, do.NULL = TRUE, prefix = "row")rownames(x) <- valuecolnames(x, do.NULL = TRUE, prefix = "col")colnames(x) <- value
x | a matrix-likeR object, with at least two dimensions for |
do.NULL | logical. If |
prefix | for created names. |
value | a valid value for that component of |
The extractor functions try to do something sensible for anymatrix-like objectx. If the object hasdimnamesthe first component is used as the row names, and the second component(if any) is used for the column names. For a data frame,rownamesandcolnames eventually callrow.names andnames respectively, but the latter are preferred.
Ifdo.NULL isFALSE, a character vector (of lengthNROW(x) orNCOL(x)) is returned in anycase, prependingprefix to simple numbers, if there are nodimnames or the corresponding component of the dimnames isNULL.
The replacement methods for arrays/matrices coerce vector and factorvalues ofvalue to character, but do not dispatch methods foras.character.
For a data frame,value forrownames should be acharacter vector of non-duplicated and non-missing names (this isenforced), and forcolnames a character vector of (preferably)unique syntactically-valid names. In both cases,value will becoerced byas.character, and settingcolnameswill convert the row names to character.
If the replacement versions are called on a matrix without anyexisting dimnames, they will add suitable dimnames. Butconstructions such as
rownames(x)[3] <- "c"
may not work unlessx already has dimnames, since this willcreate a length-3value from theNULL value ofrownames(x).
dimnames,case.names,variable.names.
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.")m2Add the following code to your website.
For more information on customizing the embed code, readEmbedding Snippets.
