EVOLUTION-MANAGER
Edit File: colnames.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Row and Column Names</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for row+colnames {base}"><tr><td>row+colnames {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Row and Column Names</h2> <h3>Description</h3> <p>Retrieve or set the row or column names of a matrix-like object. </p> <h3>Usage</h3> <pre> rownames(x, do.NULL = TRUE, prefix = "row") rownames(x) <- value colnames(x, do.NULL = TRUE, prefix = "col") colnames(x) <- value </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>a matrix-like <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> object, with at least two dimensions for <code>colnames</code>.</p> </td></tr> <tr valign="top"><td><code>do.NULL</code></td> <td> <p>logical. If <code>FALSE</code> and names are <code>NULL</code>, names are created.</p> </td></tr> <tr valign="top"><td><code>prefix</code></td> <td> <p>for created names.</p> </td></tr> <tr valign="top"><td><code>value</code></td> <td> <p>a valid value for that component of <code><a href="dimnames.html">dimnames</a>(x)</code>. For a matrix or array this is either <code>NULL</code> or a character vector of non-zero length equal to the appropriate dimension.</p> </td></tr> </table> <h3>Details</h3> <p>The extractor functions try to do something sensible for any matrix-like object <code>x</code>. If the object has <code><a href="dimnames.html">dimnames</a></code> 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, <code>rownames</code> and <code>colnames</code> eventually call <code><a href="row.names.html">row.names</a></code> and <code><a href="names.html">names</a></code> respectively, but the latter are preferred. </p> <p>If <code>do.NULL</code> is <code>FALSE</code>, a character vector (of length <code><a href="nrow.html">NROW</a>(x)</code> or <code><a href="nrow.html">NCOL</a>(x)</code>) is returned in any case, prepending <code>prefix</code> to simple numbers, if there are no dimnames or the corresponding component of the dimnames is <code>NULL</code>. </p> <p>The replacement methods for arrays/matrices coerce vector and factor values of <code>value</code> to character, but do not dispatch methods for <code>as.character</code>. </p> <p>For a data frame, <code>value</code> for <code>rownames</code> should be a character vector of non-duplicated and non-missing names (this is enforced), and for <code>colnames</code> a character vector of (preferably) unique syntactically-valid names. In both cases, <code>value</code> will be coerced by <code><a href="character.html">as.character</a></code>, and setting <code>colnames</code> will convert the row names to character. </p> <h3>Note</h3> <p>If the replacement versions are called on a matrix without any existing dimnames, they will add suitable dimnames. But constructions such as </p> <pre> rownames(x)[3] <- "c"</pre> <p>may not work unless <code>x</code> already has dimnames, since this will create a length-3 <code>value</code> from the <code>NULL</code> value of <code>rownames(x)</code>. </p> <h3>See Also</h3> <p><code><a href="dimnames.html">dimnames</a></code>, <code><a href="../../stats/html/case.names.html">case.names</a></code>, <code><a href="../../stats/html/case.names.html">variable.names</a></code>. </p> <h3>Examples</h3> <pre> 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 </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>