Skip to content

Utility function to add row names to a data frame #639

@Mullefa

Description

@Mullefa

Oftentimes, when I am working with a data frame returned from another package, important information will be encoded using the row names of the data frame. Using dplyr, this data should be added as a column (as it is dropped by the manipulation verbs). Something like the following would be useful:

# nse
add_rownames <- function(.data, col_name = "rownames") {
  col_name <- deparse(substitute(col_name))
  add_row_names_(.data, col_name)
}

# se
add_rownames_ <- function(.data, col_name = "rownames") {
  row_names <- data_frame(rownames(.data))
  names(row_names) <- col_name
  dplyr:::cbind_list(row_names, .data)
}

Maybe make the SE version generic?

Metadata

Metadata

Assignees

Labels

featurea feature request or enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions