Introduction

The make.table function in this package aids in the generation of flexible and reproducible descriptive summary tables. The results may be outputted as PDF LaTeX documents via Sweave, HTML files via knitr, or printed to the R console. A data frame must be provided, and categorical and continuous variables need to be specified separately via cat.varlist and cont.varlist, as these variables are then processed through separate summary functions. Optional inputs for headers, row names, summary statistics, p-values, captions, colored striping, etc. may be used to stylize the output. The table can be stratified by one or more variables. A note will be printed to the console if observations are omitted due to missing values of the stratifying variable(s).

As a less time-consuming (but less flexible) alternative, a data frame may be passed to quick.table, which dynamically classifies variables as either categorical or continuous and generates a complete set of summary statistics for all available variables.  

 

Installing the ‘Table1’ package

Install the package from GitHub using Hadley’s devtools package.

library(devtools)
install_github("emwozniak/Table1")
library(Table1)

 

Building a table

The examples in this tutorial use the Mayo Clinic Primary Biliary Cirrhosis Data found in the survival package.

Minimal required inputs

A data frame must be provided and the variables to be included in the table need to be specified as either categorical or continuous.

Example

library(survival)
make.table(dat          = pbc,
           strat        = "sex",
           cat.varlist  = c("stage", "trt"),
           cont.varlist = c("bili", "copper"))
##          Variable                    m                     f                Overall
##  trt                                                                               
##    Count (%)               36 (11.54%)          276 (88.46%)                    312
##    (Row %)(Col %)                                                                  
##    1              21 (13.29%) (58.33%) 137 (86.71%) (49.64%) 158 (100.00%) (50.64%)
##    2              15 ( 9.74%) (41.67%) 139 (90.26%) (50.36%) 154 (100.00%) (49.36%)
##    Missing                           8                    98                    106
##                                                                                    
##  bili                                                                              
##     Count                           44                   374                    418
##     Mean (SD)              2.87 (2.32)           3.26 (4.59)            3.22 (4.41)
##     Median (IQR)           2.05 (2.20)           1.30 (2.70)            1.40 (2.60)
##     Q1, Q3                  1.30, 3.50            0.70, 3.40             0.80, 3.40
##     Min, Max               0.60,  9.50           0.30, 28.00            0.30, 28.00
##     Missing                          0                     0                      0
##                                                                                    
##  copper                                                                            
##     Count                           36                   274                    310
##     Mean (SD)          154.28 (100.67)        90.21 ( 80.74)          97.65 (85.61)
##     Median (IQR)       134.50 (131.00)        67.00 ( 71.75)          73.00 (81.75)
##     Q1, Q3               80.75, 211.75         40.00, 111.75          41.25, 123.00
##     Min, Max             13.00, 444.00          4.00, 588.00           4.00, 588.00
##     Missing                          8                   100                    108
##                                                                                    
##  stage                                                                             
##    Count (%)               44 (10.68%)          368 (89.32%)                    412
##    (Row %)(Col %)                                                                  
##    1               3 (14.29%) ( 6.82%)  18 (85.71%) ( 4.89%)  21 (100.00%) ( 5.10%)
##    2               8 ( 8.70%) (18.18%)  84 (91.30%) (22.83%)  92 (100.00%) (22.33%)
##    3              16 (10.32%) (36.36%) 139 (89.68%) (37.77%) 155 (100.00%) (37.62%)
##    4              17 (11.81%) (38.64%) 127 (88.19%) (34.51%) 144 (100.00%) (34.95%)
##    Missing                           0                     6                      6
## 

Output options

In addition to console output (default), the table may be outputted as HTML, as in the example below below, or as LaTeX code by specifying output="latex".

Example

make.table(dat          = pbc,
           strat        = "sex",
           cat.varlist  = c("stage", "trt"),
           cont.varlist = c("bili", "copper"),
           output       = "html")
Variable m f Overall
trt
      Count (%) 36 (11.54%) 276 (88.46%) 312
      (Row %)(Col %)
      1 21 (13.29%) (58.33%) 137 (86.71%) (49.64%) 158 (100.00%) (50.64%)
      2 15 ( 9.74%) (41.67%) 139 (90.26%) (50.36%) 154 (100.00%) (49.36%)
      Missing 8 98 106
     
bili
      Count 44 374 418
      Mean (SD) 2.87 (2.32) 3.26 (4.59) 3.22 (4.41)
      Median (IQR) 2.05 (2.20) 1.30 (2.70) 1.40 (2.60)
      Q1, Q3 1.30, 3.50 0.70, 3.40 0.80, 3.40
      Min, Max 0.60, 9.50 0.30, 28.00 0.30, 28.00
      Missing 0 0 0
     
copper
      Count 36 274 310
      Mean (SD) 154.28 (100.67) 90.21 ( 80.74) 97.65 (85.61)
      Median (IQR) 134.50 (131.00) 67.00 ( 71.75) 73.00 (81.75)
      Q1, Q3 80.75, 211.75 40.00, 111.75 41.25, 123.00
      Min, Max 13.00, 444.00 4.00, 588.00 4.00, 588.00
      Missing 8 100 108
     
stage
      Count (%) 44 (10.68%) 368 (89.32%) 412
      (Row %)(Col %)
      1 3 (14.29%) ( 6.82%) 18 (85.71%) ( 4.89%) 21 (100.00%) ( 5.10%)
      2 8 ( 8.70%) (18.18%) 84 (91.30%) (22.83%) 92 (100.00%) (22.33%)
      3 16 (10.32%) (36.36%) 139 (89.68%) (37.77%) 155 (100.00%) (37.62%)
      4 17 (11.81%) (38.64%) 127 (88.19%) (34.51%) 144 (100.00%) (34.95%)
      Missing 0 6 6
     

 

Customizing statistics

Descriptive statistics

By default, all computed descriptive statistics are displayed:

Categorical variables

  • Counts of observations and missing values
  • Row and column percentages

Continuous variables

  • Counts of observations and missing values
  • Mean and standard deviation
  • Median and interquartile range
  • 25th and 75th percentiles
  • Minimum and maximum

The cat.rmstat and cont.rmstat options allow for the removal of certain descriptive statistics and accept lists of vectors as inputs to enable the display of different statistics for each variable. Options for cat.rmstat include count, miss, row, and col. For cont.rmstat, options include count, miss, meansd, mediqr, q1q3, and minmax.

Example

make.table(dat          = pbc,
           strat        = "sex",
           cat.varlist  = c("stage", "trt"),
           cat.rmstat   = list(c("row"), c("col")),
           cont.varlist = c("bili", "copper"),
           cont.rmstat  = list(c("count", "meansd", "q1q3"), c("minmax")),
           output       = "html")
Variable m f Overall
trt
      Count (%) 36 (11.54%) 276 (88.46%) 312
      (Row %)
      1 21 (13.29%) 137 (86.71%) 158 (100.00%)
      2 15 ( 9.74%) 139 (90.26%) 154 (100.00%)
      Missing 8 98 106
     
bili
      Median (IQR) 2.05 (2.20) 1.30 (2.70) 1.40 (2.60)
      Min, Max 0.60, 9.50 0.30, 28.00 0.30, 28.00
      Missing 0 0 0
     
copper
      Count 36 274 310
      Mean (SD) 154.28 (100.67) 90.21 ( 80.74) 97.65 (85.61)
      Median (IQR) 134.50 (131.00) 67.00 ( 71.75) 73.00 (81.75)
      Q1, Q3 80.75, 211.75 40.00, 111.75 41.25, 123.00
      Missing 8 100 108
     
stage
      Count (%) 44 (10.68%) 368 (89.32%) 412
      (Col %)
      1 3 ( 6.82%) 18 ( 4.89%) 21 ( 5.10%)
      2 8 (18.18%) 84 (22.83%) 92 (22.33%)
      3 16 (36.36%) 139 (37.77%) 155 (37.62%)
      4 17 (38.64%) 127 (34.51%) 144 (34.95%)
      Missing 0 6 6
     

Inferential statistics

Hypothesis tests are indicated separately for categorical and continuous variables using cat.ptype and cont.ptype, respectively. Available options for statistical testing are listed in ?stat.col and include

One-sample tests

  • t.oneway: test for mean = 0
  • wilcox.oneway: test for median = 0
  • prop.oneway: test for equal proportions (both 0.5)

Tests across strata

  • chisq: Chi-square test
  • fisher: Fisher’s exact test
  • ttest: t-test
  • anova: one-way ANOVA
  • kruskal: Kruskal-Wallis test
  • wilcox: Wilcoxon rank-sum test

Paired tests

  • ttest.pair: Paired t-test
  • wilcox.pair: Wilcoxon signed-rank test
  • mcnemar: McNemar’s test

The test used is printed beneath the calculated p-value by default, and may be excluded with the pname = FALSE option.

Example

make.table(dat          = pbc,
           strat        = "sex",
           cat.varlist  = c("stage", "trt"),
           cat.rmstat   = list(c("row"), c("col")),
           cat.ptype    = c("fisher", "chisq"),
           cont.varlist = c("bili", "copper"),
           cont.rmstat  = list(c("meansd", "q1q3"), c("minmax")),
           cont.ptype   = c("wilcox", "ttest"),
           output       = "html")
Variable m f Overall p.value
trt 0.421
      Count (%) 36 (11.54%) 276 (88.46%) 312 Chi-square
      (Row %)
      1 21 (13.29%) 137 (86.71%) 158 (100.00%)
      2 15 ( 9.74%) 139 (90.26%) 154 (100.00%)
      Missing 8 98 106
     
bili 0.029
      Count 44 374 418 Wilcoxon rank-sum
      Median (IQR) 2.05 (2.20) 1.30 (2.70) 1.40 (2.60)
      Min, Max 0.60, 9.50 0.30, 28.00 0.30, 28.00
      Missing 0 0 0
     
copper <0.001
      Count 36 274 310 t-test
      Mean (SD) 154.28 (100.67) 90.21 ( 80.74) 97.65 (85.61)
      Median (IQR) 134.50 (131.00) 67.00 ( 71.75) 73.00 (81.75)
      Q1, Q3 80.75, 211.75 40.00, 111.75 41.25, 123.00
      Missing 8 100 108
     
stage 0.777
      Count (%) 44 (10.68%) 368 (89.32%) 412 Fisher exact
      (Col %)
      1 3 ( 6.82%) 18 ( 4.89%) 21 ( 5.10%)
      2 8 (18.18%) 84 (22.83%) 92 (22.33%)
      3 16 (36.36%) 139 (37.77%) 155 (37.62%)
      4 17 (38.64%) 127 (34.51%) 144 (34.95%)
      Missing 0 6 6
     

 

Customizing descriptions

Labeling options

Row headers and column names

Short variable labels may be supplied to cat.header and cont.header. For categorical variables, factor level names may be included as lists of vectors of varying length via cat.rownames. Column names for the table overall are inputted to the colnames option, and must be indicated starting with the column of variable names. A blank header can be specified with an empty quote string.

Example

make.table(dat          = pbc,
           strat        = "sex",
           cat.varlist  = c("stage", "trt"),
           cat.header   = c("Stage", "Treatment"),
           cat.rownames = list(c("I", "II", "III", "IV"), c("D-penicillamine", "Placebo")),
           cont.varlist = c("bili", "copper"),
           cont.header  = c("Bilirubin", "Copper"),
           output       = "html")
Variable m f Overall
Treatment
      Count (%) 36 (11.54%) 276 (88.46%) 312
      (Row %)(Col %)
      D-penicillamine 21 (13.29%) (58.33%) 137 (86.71%) (49.64%) 158 (100.00%) (50.64%)
      Placebo 15 ( 9.74%) (41.67%) 139 (90.26%) (50.36%) 154 (100.00%) (49.36%)
      Missing 8 98 106
     
Bilirubin
      Count 44 374 418
      Mean (SD) 2.87 (2.32) 3.26 (4.59) 3.22 (4.41)
      Median (IQR) 2.05 (2.20) 1.30 (2.70) 1.40 (2.60)
      Q1, Q3 1.30, 3.50 0.70, 3.40 0.80, 3.40
      Min, Max 0.60, 9.50 0.30, 28.00 0.30, 28.00
      Missing 0 0 0
     
Copper
      Count 36 274 310
      Mean (SD) 154.28 (100.67) 90.21 ( 80.74) 97.65 (85.61)
      Median (IQR) 134.50 (131.00) 67.00 ( 71.75) 73.00 (81.75)
      Q1, Q3 80.75, 211.75 40.00, 111.75 41.25, 123.00
      Min, Max 13.00, 444.00 4.00, 588.00 4.00, 588.00
      Missing 8 100 108
     
Stage
      Count (%) 44 (10.68%) 368 (89.32%) 412
      (Row %)(Col %)
      I 3 (14.29%) ( 6.82%) 18 (85.71%) ( 4.89%) 21 (100.00%) ( 5.10%)
      II 8 ( 8.70%) (18.18%) 84 (91.30%) (22.83%) 92 (100.00%) (22.33%)
      III 16 (10.32%) (36.36%) 139 (89.68%) (37.77%) 155 (100.00%) (37.62%)
      IV 17 (11.81%) (38.64%) 127 (88.19%) (34.51%) 144 (100.00%) (34.95%)
      Missing 0 6 6
     

 

Captions and footers

Captions and footers may be added with the caption and footer options.

Example

make.table(dat          = pbc,
           strat        = "sex",
           cat.varlist  = c("stage", "trt"),
           cat.header   = c("Stage", "Treatment"),
           cat.rownames = list(c("I", "II", "III", "IV"), c("D-penicillamine", "Placebo")),
           cont.varlist = c("bili", "copper"),
           cont.header  = c("Bilirubin", "Copper"),
           caption      = "Primary Biliary Cirrhosis Trial",
           footer       = "Mayo Clinic 1974-1984",
           output       = "html")
Primary Biliary Cirrhosis Trial
Variable m f Overall
Treatment
      Count (%) 36 (11.54%) 276 (88.46%) 312
      (Row %)(Col %)
      D-penicillamine 21 (13.29%) (58.33%) 137 (86.71%) (49.64%) 158 (100.00%) (50.64%)
      Placebo 15 ( 9.74%) (41.67%) 139 (90.26%) (50.36%) 154 (100.00%) (49.36%)
      Missing 8 98 106
     
Bilirubin
      Count 44 374 418
      Mean (SD) 2.87 (2.32) 3.26 (4.59) 3.22 (4.41)
      Median (IQR) 2.05 (2.20) 1.30 (2.70) 1.40 (2.60)
      Q1, Q3 1.30, 3.50 0.70, 3.40 0.80, 3.40
      Min, Max 0.60, 9.50 0.30, 28.00 0.30, 28.00
      Missing 0 0 0
     
Copper
      Count 36 274 310
      Mean (SD) 154.28 (100.67) 90.21 ( 80.74) 97.65 (85.61)
      Median (IQR) 134.50 (131.00) 67.00 ( 71.75) 73.00 (81.75)
      Q1, Q3 80.75, 211.75 40.00, 111.75 41.25, 123.00
      Min, Max 13.00, 444.00 4.00, 588.00 4.00, 588.00
      Missing 8 100 108
     
Stage
      Count (%) 44 (10.68%) 368 (89.32%) 412
      (Row %)(Col %)
      I 3 (14.29%) ( 6.82%) 18 (85.71%) ( 4.89%) 21 (100.00%) ( 5.10%)
      II 8 ( 8.70%) (18.18%) 84 (91.30%) (22.83%) 92 (100.00%) (22.33%)
      III 16 (10.32%) (36.36%) 139 (89.68%) (37.77%) 155 (100.00%) (37.62%)
      IV 17 (11.81%) (38.64%) 127 (88.19%) (34.51%) 144 (100.00%) (34.95%)
      Missing 0 6 6
     
Mayo Clinic 1974-1984

 

Stylizing output

Table design (HTML)

HTML codes and colors can be included in the code for HTML output.

Example

make.table(dat          = pbc,
           strat        = "sex",
           cat.varlist  = c("stage", "trt"),
           cat.header   = c("Stage", "Treatment&Dagger;"),
           cat.rownames = list(c("I", "II", "III", "IV"), c("D-penicillamine", "Placebo")),
           cont.varlist = c("bili", "copper"),
           cont.header  = c("Bilirubin", "Copper"),
           colnames     = c(" ", "Males", "Females", "Overall"),
           caption      = "<h3><b>Primary Biliary Cirrhosis Trial&dagger;</b></h3>",
           footer       = "&dagger;Mayo Clinic 1974-1984<br>&Dagger;Randomized placebo controlled trial of the drug D-penicillamine",
           stripe.col   = "#adcbe3",
           output       = "html")

Primary Biliary Cirrhosis Trial†

Males Females Overall
Treatment‡
      Count (%) 36 (11.54%) 276 (88.46%) 312
      (Row %)(Col %)
      D-penicillamine 21 (13.29%) (58.33%) 137 (86.71%) (49.64%) 158 (100.00%) (50.64%)
      Placebo 15 ( 9.74%) (41.67%) 139 (90.26%) (50.36%) 154 (100.00%) (49.36%)
      Missing 8 98 106
     
Bilirubin
      Count 44 374 418
      Mean (SD) 2.87 (2.32) 3.26 (4.59) 3.22 (4.41)
      Median (IQR) 2.05 (2.20) 1.30 (2.70) 1.40 (2.60)
      Q1, Q3 1.30, 3.50 0.70, 3.40 0.80, 3.40
      Min, Max 0.60, 9.50 0.30, 28.00 0.30, 28.00
      Missing 0 0 0
     
Copper
      Count 36 274 310
      Mean (SD) 154.28 (100.67) 90.21 ( 80.74) 97.65 (85.61)
      Median (IQR) 134.50 (131.00) 67.00 ( 71.75) 73.00 (81.75)
      Q1, Q3 80.75, 211.75 40.00, 111.75 41.25, 123.00
      Min, Max 13.00, 444.00 4.00, 588.00 4.00, 588.00
      Missing 8 100 108
     
Stage
      Count (%) 44 (10.68%) 368 (89.32%) 412
      (Row %)(Col %)
      I 3 (14.29%) ( 6.82%) 18 (85.71%) ( 4.89%) 21 (100.00%) ( 5.10%)
      II 8 ( 8.70%) (18.18%) 84 (91.30%) (22.83%) 92 (100.00%) (22.33%)
      III 16 (10.32%) (36.36%) 139 (89.68%) (37.77%) 155 (100.00%) (37.62%)
      IV 17 (11.81%) (38.64%) 127 (88.19%) (34.51%) 144 (100.00%) (34.95%)
      Missing 0 6 6
     
†Mayo Clinic 1974-1984
‡Randomized placebo controlled trial of the drug D-penicillamine

Text style can be altered for headers, rownames, and names of statistics using header.style, factor.style, and stat.style, respectively, with the font face options of “plain”, “bold”, “italic”, and “bolditalic”.

Example

make.table(dat          = pbc,
           strat        = "sex",
           cat.varlist  = c("stage", "trt"),
           cat.header   = c("Stage", "Treatment&Dagger;"),
           cat.rownames = list(c("I", "II", "III", "IV"), c("D-penicillamine", "Placebo")),
           cont.varlist = c("bili", "copper"),
           cont.header  = c("Bilirubin", "Copper"),
           colnames     = c(" ", "Males", "Females", "Overall"),
           caption      = "<h3><b>Primary Biliary Cirrhosis Trial&dagger;</b></h3>",
           footer       = "&dagger;Mayo Clinic 1974-1984<br>&Dagger;Randomized placebo controlled trial of the drug D-penicillamine",
           stripe.col   = "#e1e9b7",
           factor.style = "plain",
           stat.style   = "italic",
           output       = "html")

Primary Biliary Cirrhosis Trial†

Males Females Overall
Treatment‡
      Count (%) 36 (11.54%) 276 (88.46%) 312
      (Row %)(Col %)
      D-penicillamine 21 (13.29%) (58.33%) 137 (86.71%) (49.64%) 158 (100.00%) (50.64%)
      Placebo 15 ( 9.74%) (41.67%) 139 (90.26%) (50.36%) 154 (100.00%) (49.36%)
      Missing 8 98 106
     
Bilirubin
      Count 44 374 418
      Mean (SD) 2.87 (2.32) 3.26 (4.59) 3.22 (4.41)
      Median (IQR) 2.05 (2.20) 1.30 (2.70) 1.40 (2.60)
      Q1, Q3 1.30, 3.50 0.70, 3.40 0.80, 3.40
      Min, Max 0.60, 9.50 0.30, 28.00 0.30, 28.00
      Missing 0 0 0
     
Copper
      Count 36 274 310
      Mean (SD) 154.28 (100.67) 90.21 ( 80.74) 97.65 (85.61)
      Median (IQR) 134.50 (131.00) 67.00 ( 71.75) 73.00 (81.75)
      Q1, Q3 80.75, 211.75 40.00, 111.75 41.25, 123.00
      Min, Max 13.00, 444.00 4.00, 588.00 4.00, 588.00
      Missing 8 100 108
     
Stage
      Count (%) 44 (10.68%) 368 (89.32%) 412
      (Row %)(Col %)
      I 3 (14.29%) ( 6.82%) 18 (85.71%) ( 4.89%) 21 (100.00%) ( 5.10%)
      II 8 ( 8.70%) (18.18%) 84 (91.30%) (22.83%) 92 (100.00%) (22.33%)
      III 16 (10.32%) (36.36%) 139 (89.68%) (37.77%) 155 (100.00%) (37.62%)
      IV 17 (11.81%) (38.64%) 127 (88.19%) (34.51%) 144 (100.00%) (34.95%)
      Missing 0 6 6
     
†Mayo Clinic 1974-1984
‡Randomized placebo controlled trial of the drug D-penicillamine

Table spanners can be used to apply groupings to rows and columns. The order of variables can be changed with varorder to facilitate grouping variables. The use of tspanner and n.tspanner correspond to the use of rgroup and n.rgroup in the htmlTable package usage vignette, and similarly for cgroup and n.cgroup. Options for multiple stacking spanners are explained at https://github.com/gforge/htmlTable.

Example

make.table(dat          = pbc,
           strat        = "sex",
           cat.varlist  = c("stage", "trt"),
           cat.header   = c("Stage", "Treatment&Dagger;"),
           cat.rownames = list(c("I", "II", "III", "IV"), c("D-penicillamine", "Placebo")),
           cont.varlist = c("bili", "copper"),
           cont.header  = c("Bilirubin", "Copper"),
           colnames     = c(" ", "Males", "Females", "Overall"),
           caption      = "<h3><b>Primary Biliary Cirrhosis Trial&dagger;</b></h3>",
           footer       = "&dagger;Mayo Clinic 1974-1984<br>&Dagger;Randomized placebo controlled 
                           trial of the drug D-penicillamine",
           stripe.col   = "#e1e9b7",
           factor.style = "plain",
           stat.style   = "italic",
           varorder     = "abc",
           tspanner     = c("<b><i>---Lab results---</i></b>", 
                            "<b><i>---Disease and treatment---</i></b>"),
           n.tspanner   = c(16, 16),
           cgroup       = c("", "Results by Sex", ""),
           n.cgroup     = c(1, 2, 1),
           output       = "html")

Primary Biliary Cirrhosis Trial†

  Results by Sex  
  Males Females   Overall
—Lab results—
Bilirubin    
      Count   44 374   418
      Mean (SD)   2.87 (2.32) 3.26 (4.59)   3.22 (4.41)
      Median (IQR)   2.05 (2.20) 1.30 (2.70)   1.40 (2.60)
      Q1, Q3   1.30, 3.50 0.70, 3.40   0.80, 3.40
      Min, Max   0.60, 9.50 0.30, 28.00   0.30, 28.00
      Missing   0 0   0
         
Copper    
      Count   36 274   310
      Mean (SD)   154.28 (100.67) 90.21 ( 80.74)   97.65 (85.61)
      Median (IQR)   134.50 (131.00) 67.00 ( 71.75)   73.00 (81.75)
      Q1, Q3   80.75, 211.75 40.00, 111.75   41.25, 123.00
      Min, Max   13.00, 444.00 4.00, 588.00   4.00, 588.00
      Missing   8 100   108
         
—Disease and treatment—
Stage    
      Count (%)   44 (10.68%) 368 (89.32%)   412
      (Row %)(Col %)    
      I   3 (14.29%) ( 6.82%) 18 (85.71%) ( 4.89%)   21 (100.00%) ( 5.10%)
      II   8 ( 8.70%) (18.18%) 84 (91.30%) (22.83%)   92 (100.00%) (22.33%)
      III   16 (10.32%) (36.36%) 139 (89.68%) (37.77%)   155 (100.00%) (37.62%)
      IV   17 (11.81%) (38.64%) 127 (88.19%) (34.51%)   144 (100.00%) (34.95%)
      Missing   0 6   6
         
Treatment‡    
      Count (%)   36 (11.54%) 276 (88.46%)   312
      (Row %)(Col %)    
      D-penicillamine   21 (13.29%) (58.33%) 137 (86.71%) (49.64%)   158 (100.00%) (50.64%)
      Placebo   15 ( 9.74%) (41.67%) 139 (90.26%) (50.36%)   154 (100.00%) (49.36%)
      Missing   8 98   106
         
†Mayo Clinic 1974-1984
‡Randomized placebo controlled
trial of the drug D-penicillamine

 

Table design (LaTeX)

The same style options for headers, rownames, and statistics available for HTML output may also be applied to LaTeX output. Furthermore, LaTeX code for symbols may be used within table code, e.g., \dagger and \ddagger.

Quick table build

Only a data frame needs to be passed to the quick.table function. The results will be printed to the console if no output option is specified. Lists of variable classifications and total removed observations will be printed. The quick.table function is a good stepping stone to use before writing code to create a more flexible table with make.table, as it displays all available categorical factor levels, etc., and does not require familiarity with the dataset.

Note that since quick.table summarizes all available variables in a dataset, any variables without need for summary should be removed.

Example

# Remove ID variable before summarizing
quickdat <- pbc[, -1]
quick.table(quickdat)
## [1] "The following variables are summarized as continuous:"
## c("time", "age", "bili", "chol", "albumin", "copper", "alk.phos", 
## "ast", "trig", "platelet", "protime")
## [1] "The following variables are summarized as categorical:"
## c("status", "trt", "sex", "ascites", "hepato", "spiders", "edema", 
## "stage")
##         Variable           Overall
##  time                             
##     Count                      418
##     Mean (SD)    1917.78 (1104.67)
##     Median (IQR) 1730.00 (1520.75)
##     Q1, Q3         1092.75, 2613.5
##     Min, Max           41.00, 4795
##     Missing                      0
##                                   
##  status                           
##    Count                       418
##    (%)                            
##    0                  232 (55.50%)
##    1                   25 ( 5.98%)
##    2                  161 (38.52%)
##    Missing                       0
##                                   
##  trt                              
##    Count                       312
##    (%)                            
##    1                  158 (50.64%)
##    2                  154 (49.36%)
##    Missing                     106
##                                   
##  age                              
##     Count                      418
##     Mean (SD)        50.74 (10.45)
##     Median (IQR)     51.00 (15.41)
##     Q1, Q3            42.83, 58.24
##     Min, Max          26.28, 78.44
##     Missing                      0
##                                   
##  sex                              
##    Count                       418
##    (%)                            
##    m                   44 (10.53%)
##    f                  374 (89.47%)
##    Missing                       0
##                                   
##  ascites                          
##    Count                       312
##    (%)                            
##    0                  288 (92.31%)
##    1                   24 ( 7.69%)
##    Missing                     106
##                                   
##  hepato                           
##    Count                       312
##    (%)                            
##    0                  152 (48.72%)
##    1                  160 (51.28%)
##    Missing                     106
##                                   
##  spiders                          
##    Count                       312
##    (%)                            
##    0                  222 (71.15%)
##    1                   90 (28.85%)
##    Missing                     106
##                                   
##  edema                            
##    Count                       418
##    (%)                            
##    0                  354 (84.69%)
##    0.5                 44 (10.53%)
##    1                   20 ( 4.78%)
##    Missing                       0
##                                   
##  bili                             
##     Count                      418
##     Mean (SD)          3.22 (4.41)
##     Median (IQR)       1.40 (2.60)
##     Q1, Q3               0.80, 3.4
##     Min, Max              0.30, 28
##     Missing                      0
##                                   
##  chol                             
##     Count                      284
##     Mean (SD)      369.51 (231.94)
##     Median (IQR)   309.50 (150.50)
##     Q1, Q3             249.50, 400
##     Min, Max          120.00, 1775
##     Missing                    134
##                                   
##  albumin                          
##     Count                      418
##     Mean (SD)          3.50 (0.42)
##     Median (IQR)       3.53 (0.53)
##     Q1, Q3              3.24, 3.77
##     Min, Max            1.96, 4.64
##     Missing                      0
##                                   
##  copper                           
##     Count                      310
##     Mean (SD)        97.65 (85.61)
##     Median (IQR)     73.00 (81.75)
##     Q1, Q3              41.25, 123
##     Min, Max             4.00, 588
##     Missing                    108
##                                   
##  alk.phos                         
##     Count                      312
##     Mean (SD)    1982.66 (2140.39)
##     Median (IQR) 1259.00 (1108.50)
##     Q1, Q3            871.50, 1980
##     Min, Max       289.00, 13862.4
##     Missing                    106
##                                   
##  ast                              
##     Count                      312
##     Mean (SD)       122.56 (56.70)
##     Median (IQR)    114.70 (71.30)
##     Q1, Q3            80.60, 151.9
##     Min, Max         26.35, 457.25
##     Missing                    106
##                                   
##  trig                             
##     Count                      282
##     Mean (SD)       124.70 (65.15)
##     Median (IQR)    108.00 (66.75)
##     Q1, Q3              84.25, 151
##     Min, Max            33.00, 598
##     Missing                    136
##                                   
##  platelet                         
##     Count                      407
##     Mean (SD)       257.02 (98.33)
##     Median (IQR)   251.00 (129.50)
##     Q1, Q3             188.50, 318
##     Min, Max            62.00, 721
##     Missing                     11
##                                   
##  protime                          
##     Count                      416
##     Mean (SD)         10.73 (1.02)
##     Median (IQR)      10.60 (1.10)
##     Q1, Q3             10.00, 11.1
##     Min, Max              9.00, 18
##     Missing                      2
##                                   
##  stage                            
##    Count                       412
##    (%)                            
##    1                   21 ( 5.10%)
##    2                   92 (22.33%)
##    3                  155 (37.62%)
##    4                  144 (34.95%)
##    Missing                       6
## 

By default, quick.table classifies variables as categorical if they are factorable into six levels or fewer, and continuous otherwise. This default can be overridden with the classlim option. Further options include stratifying variable(s), number of decimal places, column names, and zebra striping for HTML output. All labeling information is pulled directly from variable names and factor levels.

quick.table(dat      = quickdat,
            strat    = 'trt',
            colnames = c(' ', 'D-penicillamine', 'Placebo', 'Overall'),
            classlim = 4,
            dec      = 3,
            output   = "html")
## [1] "The following variables are summarized as continuous:"
## c("time", "age", "bili", "chol", "albumin", "copper", "alk.phos", 
## "ast", "trig", "platelet", "protime", "stage")
## [1] "The following variables are summarized as categorical:"
## c("status", "sex", "ascites", "hepato", "spiders", "edema")
## [1] "Total observations removed from table: 106"
## [1] "Summary of total missing stratification variable(s):"
## $trt
## [1] 106
D-penicillamine Placebo Overall
time
      Count 158 154 312
      Mean (SD) 2015.62 (1094.12) 1996.86 (1155.93) 2006.36 (1123.28)
      Median (IQR) 1895.00 (1401.50) 1811.00 (1618.25) 1839.50 (1506.25)
      Q1, Q3 1231.00, 2632.50 1153.00, 2771.25 1191.00, 2697.25
      Min, Max 41.00, 4556.00 51.00, 4523.00 41.00, 4556.00
      Missing 0 0 0
     
status
      Count (%) 158 (50.64%) 154 (49.36%) 312
      (Row %)(Col %)
      0 83 (49.40%) (52.53%) 85 (50.60%) (55.19%) 168 (100.00%) (53.85%)
      1 10 (52.63%) ( 6.33%) 9 (47.37%) ( 5.84%) 19 (100.00%) ( 6.09%)
      2 65 (52.00%) (41.14%) 60 (48.00%) (38.96%) 125 (100.00%) (40.06%)
      Missing 0 0 0
     
age
      Count 158 154 312
      Mean (SD) 51.42 (11.01) 48.58 ( 9.96) 50.02 (10.58)
      Median (IQR) 51.93 (15.92) 48.11 (14.37) 49.79 (14.48)
      Q1, Q3 42.98, 58.90 41.43, 55.80 42.24, 56.71
      Min, Max 26.28, 78.44 30.57, 74.52 26.28, 78.44
      Missing 0 0 0
     
sex
      Count (%) 158 (50.64%) 154 (49.36%) 312
      (Row %)(Col %)
      m 21 (58.33%) (13.29%) 15 (41.67%) ( 9.74%) 36 (100.00%) (11.54%)
      f 137 (49.64%) (86.71%) 139 (50.36%) (90.26%) 276 (100.00%) (88.46%)
      Missing 0 0 0
     
ascites
      Count (%) 158 (50.64%) 154 (49.36%) 312
      (Row %)(Col %)
      0 144 (50.00%) (91.14%) 144 (50.00%) (93.51%) 288 (100.00%) (92.31%)
      1 14 (58.33%) ( 8.86%) 10 (41.67%) ( 6.49%) 24 (100.00%) ( 7.69%)
      Missing 0 0 0
     
hepato
      Count (%) 158 (50.64%) 154 (49.36%) 312
      (Row %)(Col %)
      0 85 (55.92%) (53.80%) 67 (44.08%) (43.51%) 152 (100.00%) (48.72%)
      1 73 (45.62%) (46.20%) 87 (54.37%) (56.49%) 160 (100.00%) (51.28%)
      Missing 0 0 0
     
spiders
      Count (%) 158 (50.64%) 154 (49.36%) 312
      (Row %)(Col %)
      0 113 (50.90%) (71.52%) 109 (49.10%) (70.78%) 222 (100.00%) (71.15%)
      1 45 (50.00%) (28.48%) 45 (50.00%) (29.22%) 90 (100.00%) (28.85%)
      Missing 0 0 0
     
edema
      Count (%) 158 (50.64%) 154 (49.36%) 312
      (Row %)(Col %)
      0 132 (50.19%) (83.54%) 131 (49.81%) (85.06%) 263 (100.00%) (84.29%)
      0.5 16 (55.17%) (10.13%) 13 (44.83%) ( 8.44%) 29 (100.00%) ( 9.29%)
      1 10 (50.00%) ( 6.33%) 10 (50.00%) ( 6.49%) 20 (100.00%) ( 6.41%)
      Missing 0 0 0
     
bili
      Count 158 154 312
      Mean (SD) 2.87 (3.63) 3.65 (5.28) 3.26 (4.53)
      Median (IQR) 1.40 (2.40) 1.30 (2.88) 1.35 (2.62)
      Q1, Q3 0.80, 3.20 0.72, 3.60 0.80, 3.42
      Min, Max 0.30, 20.00 0.30, 28.00 0.30, 28.00
      Missing 0 0 0
     
chol
      Count 140 144 284
      Mean (SD) 365.01 (209.54) 373.88 (252.48) 369.51 (231.94)
      Median (IQR) 315.50 (169.25) 303.50 (122.75) 309.50 (150.50)
      Q1, Q3 247.75, 417.00 254.25, 377.00 249.50, 400.00
      Min, Max 127.00, 1712.00 120.00, 1775.00 120.00, 1775.00
      Missing 18 10 28
     
albumin
      Count 158 154 312
      Mean (SD) 3.52 (0.44) 3.52 (0.40) 3.52 (0.42)
      Median (IQR) 3.56 (0.62) 3.54 (0.44) 3.55 (0.49)
      Q1, Q3 3.21, 3.83 3.34, 3.78 3.31, 3.80
      Min, Max 2.10, 4.64 1.96, 4.38 1.96, 4.64
      Missing 0 0 0
     
copper
      Count 157 153 310
      Mean (SD) 97.64 (90.59) 97.65 (80.49) 97.65 (85.61)
      Median (IQR) 73.00 (81.00) 73.00 (96.00) 73.00 (81.75)
      Q1, Q3 40.00, 121.00 43.00, 139.00 41.25, 123.00
      Min, Max 9.00, 588.00 4.00, 558.00 4.00, 588.00
      Missing 1 1 2
     
alk.phos
      Count 158 154 312
      Mean (SD) 2021.30 (2183.44) 1943.01 (2101.69) 1982.66 (2140.39)
      Median (IQR) 1214.50 (1187.25) 1283.00 (1027.25) 1259.00 (1108.50)
      Q1, Q3 840.75, 2028.00 922.50, 1949.75 871.50, 1980.00
      Min, Max 369.00, 11552.00 289.00, 13862.40 289.00, 13862.40
      Missing 0 0 0
     
ast
      Count 158 154 312
      Mean (SD) 120.21 (54.52) 124.97 (58.93) 122.56 (56.70)
      Median (IQR) 111.60 (74.79) 117.40 (68.12) 114.70 (71.30)
      Q1, Q3 76.73, 151.51 83.78, 151.90 80.60, 151.90
      Min, Max 26.35, 338.00 28.38, 457.25 26.35, 457.25
      Missing 0 0 0
     
trig
      Count 139 143 282
      Mean (SD) 124.14 (71.54) 125.25 (58.52) 124.70 (65.15)
      Median (IQR) 106.00 (61.50) 113.00 (70.50) 108.00 (66.75)
      Q1, Q3 84.50, 146.00 84.50, 155.00 84.25, 151.00
      Min, Max 33.00, 598.00 44.00, 432.00 33.00, 598.00
      Missing 19 11 30
     
platelet
      Count 156 152 308
      Mean (SD) 258.75 (100.32) 265.20 ( 90.73) 261.94 (95.61)
      Median (IQR) 255.00 (132.50) 259.50 (115.75) 257.00 (122.75)
      Q1, Q3 189.50, 322.00 206.75, 322.50 199.75, 322.50
      Min, Max 62.00, 563.00 71.00, 487.00 62.00, 563.00
      Missing 2 2 4
     
protime
      Count 158 154 312
      Mean (SD) 10.65 (0.85) 10.80 (1.14) 10.73 (1.00)
      Median (IQR) 10.60 (0.97) 10.60 (1.40) 10.60 (1.10)
      Q1, Q3 10.03, 11.00 10.00, 11.40 10.00, 11.10
      Min, Max 9.00, 14.10 9.20, 17.10 9.00, 17.10
      Missing 0 0 0
     
stage
      Count 158 154 312
      Mean (SD) 2.97 (0.94) 3.09 (0.81) 3.03 (0.88)
      Median (IQR) 3.00 (2.00) 3.00 (1.00) 3.00 (2.00)
      Q1, Q3 2.00, 4.00 3.00, 4.00 2.00, 4.00
      Min, Max 1.00, 4.00 1.00, 4.00 1.00, 4.00
      Missing 0 0 0