Skip to content

sean-cho/demtables

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

demtables

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 ~ .)
##       [,1]       [,2]  [,3]             [,4]             [,5]    
##  [1,] ""         ""    "1"              "2"              "pvalue"
##  [2,] "N"        ""    "13"             "13"             ""      
##  [3,] "Futime"   ""    ""               ""               ""      
##  [4,] ""         ""    "517.31 (346.9)" "681.77 (324.7)" "0.22"  
##  [5,] "Fustat"   ""    ""               ""               ""      
##  [6,] ""         ""    "0.54 (0.5)"     "0.38 (0.5)"     "0.45"  
##  [7,] "Age"      ""    ""               ""               ""      
##  [8,] ""         ""    "55.73 (13.5)"   "56.60 (5.4)"    "0.83"  
##  [9,] "Resid.ds" ""    ""               ""               ""      
## [10,] ""         "no"  "5 (38.5)"       "6 (46.2)"       "1.00"  
## [11,] ""         "yes" "8 (61.5)"       "7 (53.8)"       ""      
## [12,] "Ecog.ps"  ""    ""               ""               ""      
## [13,] ""         ""    "1.46 (0.5)"     "1.46 (0.5)"     "1.00"

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)
##      [,1]       [,2]  [,3]           [,4]          [,5]    
## [1,] ""         ""    "1"            "2"           "pvalue"
## [2,] "N"        ""    "13"           "13"          ""      
## [3,] "Age"      ""    ""             ""            ""      
## [4,] ""         ""    "55.73 (13.5)" "56.60 (5.4)" "0.83"  
## [5,] "Resid.ds" ""    ""             ""            ""      
## [6,] ""         "no"  "5 (38.5)"     "6 (46.2)"    "1.00"  
## [7,] ""         "yes" "8 (61.5)"     "7 (53.8)"    ""

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')
Ovarian data
1 2 pvalue
N 13 13
Age
55.73 (13.5) 56.60 (5.4) 0.83
Resid.ds
no 5 (38.5) 6 (46.2) 1.00
yes 8 (61.5) 7 (53.8)

About

Make demographic tables.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages