Learn R Programming

sjtable2df (version 0.0.5)

xtab2df: xtab2df

Description

Convert table from sjPlot::tab_xtab to R data.frame or knitr::kable

Usage

xtab2df(xtab, output = "data.table", threeparttable = FALSE, ...)

Value

The table is returned as an R object of the type specified with the output argument.

Arguments

xtab

A contingency table, created with sjPlot::tab_xtab.

output

A character vector. Allowed values are: "data.table" (default), "data.frame" or "kable". The function's return value is of the respective type.

threeparttable

Boolean value indicating if a threeparttable scheme should be used.

...

Further arguments to be passed to kableExtra::kbl.

Examples

Run this code
if (requireNamespace("sjPlot", quietly = TRUE)) {
  set.seed(1)
  dataset <- data.table::data.table(
    "var1" = sample(
      x = c("yes", "no"),
      size = 100,
      replace = TRUE,
      prob = c(.3, .7)
    ),
    "var2" = sample(
      x = c("yes", "no"),
      size = 100,
      replace = TRUE
    )
  )

  xtab <- sjPlot::tab_xtab(
    var.row = dataset$var1,
    var.col = dataset$var2,
    show.summary = TRUE,
    use.viewer = FALSE
  )

  sjtable2df::xtab2df(xtab = xtab)
}

Run the code above in your browser using DataLab