R/transpose_df.R

Defines functions transpose_df

Documented in transpose_df

#' Transpose a data frame
#'
#' Returns a list of lists, where each list contains a row.
#'
#' @param x The data frame.
#'
#' @return A list.
#' @export
#'
#' @examples
#' limonaid::transpose_df(
#'   mtcars[1:3, 1:3]
#' );
transpose_df <- function(x) {
  if (!inherits(x, "data.frame")) {
    stop("You have to provide a data frame!");
  }
  return(apply(x, 1, as.list, simplify = FALSE));
}

Try the limonaid package in your browser

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

limonaid documentation built on June 10, 2025, 9:10 a.m.