Skip to contents

This function converts a specified column of a data frame to row names, ensuring uniqueness if necessary.

Usage

colToRownames(df, col, .remove = TRUE, .uniqueSep = ".")

Arguments

df

A data frame.

col

A character string specifying the name of the column to convert to row names.

.remove

A logical indicating whether to remove the selected column after converting to row names. Default is TRUE.

.uniqueSep

A character string to separate duplicate row names when ensuring uniqueness with make.unique(). Default is ".".

Value

A data frame with the specified column as row names. If .remove is TRUE, the original column is removed.

Examples

# Convert the 'ID' column to row names
df <- data.frame(ID = c("A", "B", "C"), Value = c(10, 20, 30))
colToRownames(df, "ID")
#>   Value
#> A    10
#> B    20
#> C    30
# Convert the 'ID' column to row names and keep the column
df <- data.frame(ID = c("A", "B", "C"), Value = c(10, 20, 30))
colToRownames(df, "ID", .remove = FALSE)
#>   ID Value
#> A  A    10
#> B  B    20
#> C  C    30