Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Mullefa opened this issue Sep 27, 2014 · 0 comments

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

Mullefa opened this issue Sep 27, 2014 · 0 comments


Copy link

@Mullefa Mullefa commented Sep 27, 2014

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?

@hadley hadley added the feature label Sep 30, 2014
@hadley hadley added this to the 0.3.1 milestone Sep 30, 2014
@hadley hadley self-assigned this Sep 30, 2014
@hadley hadley closed this in be7e622 Nov 20, 2014
krlmlr pushed a commit to krlmlr/dplyr that referenced this issue Mar 2, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jun 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants