| Title: | Convert 'sjPlot' HTML-Tables to R 'data.frame' |
|---|---|
| Description: | A small set of helper functions to convert 'sjPlot' HTML-tables to R data.frame objects / knitr::kable-tables. |
| Authors: | Lorenz A. Kapsner [cre, aut, cph] (ORCID: <https://orcid.org/0000-0003-1866-860X>) |
| Maintainer: | Lorenz A. Kapsner <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.0.5 |
| Built: | 2026-05-18 09:05:25 UTC |
| Source: | https://github.com/kapsner/sjtable2df |
Convert table from sjPlot::tab_model to R data.frame or
knitr::kable
mtab2df(mtab, n_models, output = "data.table", ...)mtab2df(mtab, n_models, output = "data.table", ...)
mtab |
A model table, created with |
n_models |
An integer, specifiying the number of models in the table. |
output |
A character vector. Allowed values are: "data.table" (default), "data.frame" or "kable". The function's return value is of the respective type. |
... |
Further arguments to be passed to |
The table is returned as an R object of the type specified with
the output argument.
if (requireNamespace("sjPlot", quietly = TRUE)) { set.seed(1) dataset <- data.table::data.table( "var1" = factor(sample( x = c("yes", "no"), size = 100, replace = TRUE, prob = c(.3, .7) )), "var2" = factor(sample( x = c("yes", "no"), size = 100, replace = TRUE )), "var3" = rnorm(100) ) # models m0 <- stats::glm( var1 ~ 1, data = dataset, family = binomial(link = "logit") ) m1 <- stats::glm( var1 ~ var2, data = dataset, family = binomial(link = "logit") ) m2 <- stats::glm( var1 ~ var2 + var3, data = dataset, family = binomial(link = "logit") ) m_table <- sjPlot::tab_model(m0, m1, m2, show.aic = TRUE) final_tab <- sjtable2df::mtab2df(mtab = m_table, n_models = 3) }if (requireNamespace("sjPlot", quietly = TRUE)) { set.seed(1) dataset <- data.table::data.table( "var1" = factor(sample( x = c("yes", "no"), size = 100, replace = TRUE, prob = c(.3, .7) )), "var2" = factor(sample( x = c("yes", "no"), size = 100, replace = TRUE )), "var3" = rnorm(100) ) # models m0 <- stats::glm( var1 ~ 1, data = dataset, family = binomial(link = "logit") ) m1 <- stats::glm( var1 ~ var2, data = dataset, family = binomial(link = "logit") ) m2 <- stats::glm( var1 ~ var2 + var3, data = dataset, family = binomial(link = "logit") ) m_table <- sjPlot::tab_model(m0, m1, m2, show.aic = TRUE) final_tab <- sjtable2df::mtab2df(mtab = m_table, n_models = 3) }
Convert table from sjPlot::tab_xtab to R data.frame or
knitr::kable
xtab2df(xtab, output = "data.table", threeparttable = FALSE, ...)xtab2df(xtab, output = "data.table", threeparttable = FALSE, ...)
xtab |
A contingency table, created with |
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 |
The table is returned as an R object of the type specified with
the output argument.
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) }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) }