EVOLUTION-MANAGER
Edit File: row.names.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: Get and Set Row Names for Data Frames</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.names {base}"><tr><td>row.names {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Get and Set Row Names for Data Frames</h2> <h3>Description</h3> <p>All data frames have a row names attribute, a character vector of length the number of rows with no duplicates nor missing values. </p> <p>For convenience, these are generic functions for which users can write other methods, and there are default methods for arrays. The description here is for the <code>data.frame</code> method. </p> <p><code>`.rowNamesDF<-`</code> is a (non-generic replacement) function to set row names for data frames, with extra argument <code>make.names</code>. This function only exists as workaround as we cannot easily change the <code>row.names<-</code> generic without breaking legacy code in existing packages. </p> <h3>Usage</h3> <pre> row.names(x) row.names(x) <- value .rowNamesDF(x, make.names=FALSE) <- value </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>object of class <code>"data.frame"</code>, or any other class for which a method has been defined.</p> </td></tr> <tr valign="top"><td><code>make.names</code></td> <td> <p><code><a href="logical.html">logical</a></code>, i.e., one of <code>FALSE, NA, TRUE</code>, indicating what should happen if the specified row names, i.e., <code>value</code>, are invalid, e.g., duplicated or <code>NA</code>. The default (is back compatible), <code>FALSE</code>, will signal an error, where <code>NA</code> will “automatic” row names and <code>TRUE</code> will call <code><a href="make.names.html">make.names</a>(value, unique=TRUE)</code> for constructing valid names.</p> </td></tr> <tr valign="top"><td><code>value</code></td> <td> <p>an object to be coerced to character unless an integer vector. It should have (after coercion) the same length as the number of rows of <code>x</code> with no duplicated nor missing values. <code>NULL</code> is also allowed: see ‘Details’.</p> </td></tr> </table> <h3>Details</h3> <p>A data frame has (by definition) a vector of <em>row names</em> which has length the number of rows in the data frame, and contains neither missing nor duplicated values. Where a row names sequence has been added by the software to meet this requirement, they are regarded as ‘automatic’. </p> <p>Row names are currently allowed to be integer or character, but for backwards compatibility (with <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> <= 2.4.0) <code>row.names</code> will always return a character vector. (Use <code>attr(x, "row.names")</code> if you need to retrieve an integer-valued set of row names.) </p> <p>Using <code>NULL</code> for the value resets the row names to <code>seq_len(nrow(x))</code>, regarded as ‘automatic’. </p> <h3>Value</h3> <p><code>row.names</code> returns a character vector. </p> <p><code>row.names<-</code> returns a data frame with the row names changed. </p> <h3>Note</h3> <p><code>row.names</code> is similar to <code><a href="colnames.html">rownames</a></code> for arrays, and it has a method that calls <code>rownames</code> for an array argument. </p> <p>Row names of the form <code>1:n</code> for <code>n > 2</code> are stored internally in a compact form, which might be seen from C code or by deparsing but never via <code>row.names</code> or <code><a href="attr.html">attr</a>(x, "row.names")</code>. Additionally, some names of this sort are marked as ‘automatic’ and handled differently by <code><a href="matrix.html">as.matrix</a></code> and <code><a href="data.matrix.html">data.matrix</a></code> (and potentially other functions). (All zero-row data frames are regarded as having automatic row.names.) </p> <h3>References</h3> <p>Chambers, J. M. (1992) <em>Data for models.</em> Chapter 3 of <em>Statistical Models in S</em> eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole. </p> <h3>See Also</h3> <p><code><a href="data.frame.html">data.frame</a></code>, <code><a href="colnames.html">rownames</a></code>, <code><a href="names.html">names</a></code>. </p> <p><code>.row_names_info</code> for the internal representations. </p> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>