Learn R Programming

qwraps2 (version 0.1.2)

qable: Qable: an extended verion of knitr::kable

Description

Create a simple table via kable with row groups and rownames similar to those of hmisc::latex or htmlTable::htmlTable.

Usage

qable(x, rgroup, rnames, cnames, markup = getOption("qwraps2_markup",
  "latex"), ...)

Arguments

x
matrix or data.frame to be turned into a qable
rgroup
a named numeric vector with the name of the row group and the number of rows within the group. sum(rowgroup) == nrow(x).
rnames
a character vector of the row names
cnames
column names
markup
the markup language to use
...
additional arguments passed to knitr::table

Value

  • a character vector of the formatted numbers

Details

TO DO

See Also

hmisc::latex, htmlTable::htmlTable

Examples

Run this code
library(dplyr)

this_summary <- function(.data) {
  summarize(.data,
            qwraps2::frmt(min(mpg)),
            qwraps2::frmt(median(mpg)),
            qwraps2::frmt(max(mpg)),
            qwraps2::frmt(min(hp)),
            qwraps2::frmt(max(hp)),
            qwraps2::frmt(mean(wt)))
}

mtcars$cyl_factor <- factor(mtcars$cyl, levels = c(4, 6, 8))

tab <- cbind(mtcars %>% this_summary %>% t,
             mtcars %>% group_by(cyl_factor) %>% this_summary %>% t %>% {.[-1, ]})

rwgrp <- c("Miles Per Gallon" = 3, "Horse Power" = 2, "Weight" = 1)
rwnms <- c("Min MPG", "Median MPG", "Max MPG", "Min HP", "Max HP", "Mean Weight")
cnms  <- c("All mtcars", paste(levels(mtcars$cyl_factor), "Cyl"))

qable(tab, rwgrp, rwnms, cnms, markup = "latex")
qable(tab, rwgrp, rwnms, cnms, markup = "markdown")

Run the code above in your browser using DataLab