row.names {base} | R Documentation |
All data frames have a row names attribute, a character vector of length the number of rows with no duplicates nor missing values.
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 data.frame
method.
row.names(x) row.names(x) <- value
x |
object of class "data.frame" , or any other class for
which a method has been defined. |
value |
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 x with no duplicated nor missing values.
NULL is also allowed: see Details. |
A data frame has (by definition) a vector of row names which has length the number of rows in the data frame, and contains neither missing nor duplicated values.
Prior to R 2.4.0, row names were character. As from R 2.4.0, they
are allowed to be integer or character, but for backwards
compatibility row.names
will always return a character vector.
(Use attr(x, "row.names")
if you need the actual value.)
Using NULL
for the value resets the row names to
seq_len(nrow(x))
.
row.names
returns a character vector.
row.names<-
returns a data frame with the row names changed.
row.names
is similar to rownames
for arrays, and
it has a method that calls rownames
for an array argument.
Row names of the form 1:n
for n > 2
are stored
internally in a compact form, which might be seen from C code or by
deparsing but never via row.names
or
attr(x, "row.names")
.
Chambers, J. M. (1992) Data for models. Chapter 3 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.