Skip to contents

This function converts the row names of a data frame to a specified column. Note that if the specified column already exists, it is overwritten.

Usage

rownamesToCol(df, colname = "rownames")

Arguments

df

A data frame.

colname

A character string specifying the name of the new column to contain the row names. Defaults to "rownames".

Value

A data frame with the row names converted to a column.

Examples

# Convert row names to a column named 'ID'
df <- data.frame(Value = c(10, 20, 30))
rownames(df) <- c("A", "B", "C")
rownamesToCol(df, "ID")
#>   Value ID
#> 1    10  A
#> 2    20  B
#> 3    30  C