R/adds.R

Defines functions add_rowindex

Documented in add_rowindex

#' Add a column of row numbers to a data frame
#'
#' @param x A data frame
#' @return The same data frame with a column of 1-based integers named `.row`.
#' @examplesIf !parsnip:::is_cran_check()
#' mtcars %>% add_rowindex()
#' @export
add_rowindex <- function(x) {
  if (!is.data.frame(x)) {
    rlang::abort("`x` should be a data frame.")
  }
  x <- dplyr::mutate(x, .row = seq_len(nrow(x)))
  x
}

Try the parsnip package in your browser

Any scripts or data that you put into this service are public.

parsnip documentation built on Aug. 18, 2023, 1:07 a.m.