Learn R Programming

FastUtils (version 0.2.1)

colToRownames: Convert a Column to Row Names

Description

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

Usage

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

Value

A data frame with the specified column as row names. If .remove

is TRUE, the original column is removed.

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 ".".

See Also

mutateToRownames()

Examples

Run this code
# Convert the 'ID' column to row names
df <- data.frame(ID = c("A", "B", "C"), Value = c(10, 20, 30))
colToRownames(df, "ID")
# 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)

Run the code above in your browser using DataLab