Movatterモバイル変換


[0]ホーム

URL:


rdrr.io

colnames: Row and Column Names

row+colnamesR 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) <- valuecolnames(x, do.NULL = TRUE, prefix = "col")colnames(x) <- value

Arguments

x

a matrix-likeR object, with at least two dimensions forcolnames.

do.NULL

logical. IfFALSE and names areNULL, names are created.

prefix

for created names.

value

a valid value for that component ofdimnames(x). For a matrix or array this is eitherNULL or a character vector of non-zero length equal to theappropriate dimension.

Details

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.

Note

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).

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

What can we improve?

R Package Documentation

Browse R Packages

We want your feedback!

Note that we can't provide technical support on individual packages. You should contact the package authors for that.

 
Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, readEmbedding Snippets.

Close

[8]ページ先頭

©2009-2026 Movatter.jp