Learn R Programming

table1

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

Installation

To install from CRAN:

install.packages("table1")

To install the latest development version directly from GitHub:

require(devtools)
devtools::install_github("benjaminrich/table1")

Getting Started

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

Example

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.

require(table1)
require(survival)

dat <- subset(survival::pbc, !is.na(trt))  # 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)

Copy Link

Version

Install

install.packages('table1')

Monthly Downloads

6,123

Version

1.5.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Benjamin Rich

Last Published

September 19th, 2025

Functions in table1 (1.5.1)

signif_pad

Round numbers with 0-padding.
t1kable

Convert a table1 object to kabelExtra.
render.varlabel

Render variable labels for default table1 output.
render.default

Render values for table output.
stats.apply.rounding

Apply rounding to basic descriptive statistics.
subsetp

Subset function that preserves column attributes.
stats.default

Compute some basic descriptive statistics.
render.missing.default

Render missing values for table output.
render.strat

Render strata labels for default table1 output.
t1read

Read and augment data with extended metadata attributes
weighted

A simple class for weighted data.
table.rows

Convert to HTML table rows.
table1

Generate an HTML table of descriptive statistics.
update_html

Update HTML.
units

Units attribute.
as.data.frame.table1

Convert a table1 object to a data.frame.
factorp

Factor creation function that preserves column attributes.
knit_print.table1

Method for printing in a knitr context.
indexed

A simple class for indexed data.
indices

Extract indices from and indexed object.
print.table1

Print table1 object.
label

Label attribute.
parse.abbrev.render.code

Parse abbreviated code for rendering table output.
render.categorical.default

Render categorical values for table output.
eqcut

Cut a continuous variable into equal-sized groups.
render.continuous.default

Render continuous values for table output.
t1flex

Convert a table1 object to flextable.