R/table2dataframe.R

Defines functions table2dataframe

Documented in table2dataframe

#' table2dataframe
#'
#' Converts a table to a full data frame.
#'
#' @param tab table: contingency table
#' @param ...  further parameters given to [base::as.data.frame.table()]
#'
#' @md
#' @return a data frame with `sum(tab)` rows and `length(dim(tab))` cols
#' @export
#'
#' @examples
#' table2dataframe(Titanic)
table2dataframe <- function(tab, ...) {
  stopifnot("table" %in% class(tab))
  df    <- as.data.frame(tab, ...)
  index <- rep(1:nrow(df), df$Freq)
  df[index,-ncol(df)]
}

Try the smvgraph package in your browser

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

smvgraph documentation built on Nov. 9, 2021, 9:06 a.m.