All data frames have row names, a character vector of length the number of rows with no duplicates nor missing values.
There are generic functions for getting and setting row names,
with default methods for arrays.
The description here is for the
`.rowNamesDF<-` is a (non-generic replacement) function to set
row names for data frames, with extra argument
This function only exists as workaround as we cannot easily change the
row.names<- generic without breaking legacy code in existing packages.
1 2 3
object of class
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
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. Where a row names sequence has been added by the software to meet this requirement, they are regarded as ‘automatic’.
Row names are currently allowed to be integer or character, but
for backwards compatibility (with R <= 2.4.0)
always return a character vector. (Use
attr(x, "row.names") if
you need to retrieve an integer-valued set of row names.)
NULL for the value resets the row names to
seq_len(nrow(x)), regarded as ‘automatic’.
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
n > 2 are stored
internally in a compact form, which might be seen from C code or by
deparsing but never via
attr(x, "row.names"). Additionally, some names of this
sort are marked as ‘automatic’ and handled differently by
data.matrix (and potentially
other functions). (All zero-row data frames are regarded as having
automatic 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.
.row_names_info for the internal representations.
1 2 3 4 5 6 7 8 9 10
## To illustrate the note: df <- data.frame(x = c(TRUE, FALSE, NA, NA), y = c(12, 34, 56, 78)) row.names(df) <- 1 : 4 attr(df, "row.names") deparse(df) ## (Compact storage, not regarded as automatic.) row.names(df) <- NULL attr(df, "row.names") deparse(df) ## (Compact storage, regarded as automatic.)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.