Tables of Descriptive Statistics in HTML

Create HTML tables of descriptive statistics, as one would expect to see as the first table (i.e. "Table 1") in a medical/epidemiological journal article.

Travis-CI Build Status

An R package for generating tables of descriptive statistics in HTML.


To install from CRAN:


To install the latest development version directly from GitHub:


Getting Started

An introduction to the package with examples is provided in the vignette.


For this example, we will use data from the Mayo Clinic trial in primary biliary cirrhosis (PBC) of the liver found in the survival package.

dat <- subset(survival::pbc, !  # Exclude subjects not randomized
dat$trt     <- factor(dat$trt, levels=1:2, labels=c("D-penicillamine", "Placebo"))
dat$sex     <- factor(dat$sex, levels=c("m", "f"), labels=c("Male", "Female"))
dat$stage   <- factor(dat$stage, levels=1:4, labels=paste("Stage", 1:4))
dat$edema   <- factor(dat$edema, levels=c(0, 0.5, 1),
                      labels=c("No edema",
                               "Untreated or successfully treated",
                               "Edema despite diuretic therapy"))
dat$spiders <- as.logical(dat$spiders)
dat$hepato  <- as.logical(dat$hepato)
dat$ascites <- as.logical(dat$ascites)
label(dat$age)      <- "Age (y)"
label(dat$sex)      <- "Sex"
label(dat$stage)    <- "Histologic stage of disease"
label(dat$edema)    <- "Edema status"
label(dat$spiders)  <- "Blood vessel malformations in the skin"
label(dat$hepato)   <- "Presence of hepatomegaly or enlarged liver"
label(dat$ascites)  <- "Presence of ascites"
label(dat$platelet) <- "Platelet count (&times; 10<sup>9</sup> per liter)"
label(dat$protime)  <- "Standardised blood clotting time"
label(dat$albumin)  <- "Serum albumin (g/dL)"
label(dat$alk.phos) <- "Alkaline phosphotase (U/L)"
label(dat$ast)      <- "Aspartate aminotransferase (U/mL)"
label(dat$bili)     <- "Serum bilirubin (mg/dL)"
label(dat$chol)     <- "Serum cholesterol (mg/dL)"
label(dat$copper)   <- "Urine copper (&mu;g/day)"
label(dat$trig)     <- "Triglycerides (mg/dL)"
table1(~ age + sex + stage + edema + spiders + hepato + ascites +
         platelet + protime + albumin + alk.phos + ast + bili + chol +
         copper + trig | trt, data=dat)

Example result: table of descriptive statistics from pbc data


table1 1.1

  • Added quantile.type argument to stats.default to allow selecting which quantile type is computed.

  • Special handling for "0%" and "100%" in stats.apply.rounding so that no decimals are shown.

  • droplevels now works properly with nested grouping.

  • table1 now returns a character string (containing HTML). A print method handles the printing. There is no longer a need to use capture.output to embed table1 in a shiny app.

  • Removed standalone option as it is no longer needed.

  • Use htmltools functionality to print.

  • Preview in RStudio notebook now works (issue #7).

  • Added knit_print method. No need to specify results="asis" chunk option anymore when knitting.

  • Default CSS is included automatically. It can still be overridden by specifying a custom stylesheet in R Markdown.

  • Changed notation from upper case "Q" to small case "q" for percentiles in stats.default.

  • Q1 and Q3 are now aliases for q25 and q75 respectively in stats.default.

  • Tertiles added to stats.default.

  • New function eqcut for creating equal-sized categories from continuous variables.

  • New footnote argument for adding a footnote to the table.

  • The vignette has been expanded with new examples and the documentation improved.

table1 1.0

  • This is the initial release of table1 on CRAN.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


1.4.2 by Benjamin Rich, 8 months ago

Report a bug at

Browse source code at

Authors: Benjamin Rich [aut, cre, cph]

Documentation:   PDF Manual  

GPL-3 license

Imports stats, Formula, knitr, htmltools, yaml

Suggests boot, MatchIt, rmarkdown, printr, kableExtra, flextable

Imported by coveffectsplot, ggquickeda, rUM.

Suggested by ttt, yamlet.

See at CRAN