rownames

0th

Percentile

Tools for working with row names

While a tibble can have row names (e.g., when converting from a regular data frame), they are removed when subsetting with the [ operator. A warning will be raised when attempting to assign non-NULL row names to a tibble. Generally, it is best to avoid row names, because they are basically a character column with different semantics to every other column. These functions allow to you detect if a data frame has row names (has_rownames()), remove them (remove_rownames()), or convert them back-and-forth between an explicit column (rownames_to_column() and column_to_rownames()). Also included is rowid_to_column() which adds a column at the start of the dataframe of ascending sequential row ids starting at 1. Note that this will remove any existing row names.

Usage
has_rownames(df)

remove_rownames(df)

rownames_to_column(df, var = "rowname")

rowid_to_column(df, var = "rowid")

column_to_rownames(df, var = "rowname")

Arguments
df
A data frame
var
Name of column to use for rownames.
Details

In the printed output, the presence of row names is indicated by a star just above the row numbers.

Aliases
  • rownames
  • has_rownames
  • remove_rownames
  • rownames_to_column
  • rowid_to_column
  • column_to_rownames
Examples
has_rownames(mtcars)
has_rownames(iris)
has_rownames(remove_rownames(mtcars))

head(rownames_to_column(mtcars))

mtcars_tbl <- as_tibble(rownames_to_column(mtcars))
mtcars_tbl
column_to_rownames(as.data.frame(mtcars_tbl))
Documentation reproduced from package tibble, version 1.3.3, License: MIT + file LICENSE

Community examples

Looks like there are no examples yet.