demtables is a package for making simple demographic tables.

Installation

Installation is simplest through devtools::install_github. The package depends on dplyr, tidyr, htmlTable, and formula.tools.

devtools::install_github('sean-cho/demtables')

Usage

Make dem tables

The main workhorse of the demtables package is the function dem_table which takes a data.frame and expression as an argument.

library(demtables)
library(dplyr)
library(survival)
data(ovarian)
ovarian %>% 
  mutate(resid.ds = ifelse(resid.ds == 1,'no','yes'), rx = factor(rx)) %>% 
  dem_table(rx ~ .)

Alternatively, you could select specific variables.

ovarian %>% 
  mutate(resid.ds = ifelse(resid.ds == 1,'no','yes'), rx = factor(rx)) %>% 
  dem_table(rx ~ age + resid.ds)

HTML output with proper design

The make_dem_table and view_dem_table functions create HTML tables that will be displayed in the Viewer if you use RStudio. make_dem_table can be used directly in HTML Markdowns.

ovarian %>% 
  mutate(resid.ds = ifelse(resid.ds == 1,'no','yes'), rx = factor(rx)) %>% 
  make_dem_table(rx ~ age + resid.ds, 'Ovarian data')


sean-cho/demtables documentation built on March 15, 2023, 7:59 p.m.