DemographicTable {DemographicTable}  R Documentation 
Create Demographic Table
Description
Create a demographic table with simple summary statistics, with optional comparison(s) over one or more groups.
Usage
DemographicTable(data, ...)
## S3 method for class 'data.frame'
DemographicTable(
data,
data.name = substitute(data),
groups = NULL,
keep_missing_group = TRUE,
exclude = NULL,
exclude_pattern,
include,
include_pattern,
paired = FALSE,
robust = TRUE,
overall = TRUE,
compare = TRUE,
pairwise = 3L,
...
)
Arguments
data 

... 
additional parameters, currently not in use 
data.name 
character scalar, or the argument call of 
groups 
character scalar or vector,
the name(s) of subgroup(s) for which the summary statistics are to be provided.
Default 
keep_missing_group 
logical scalar.
If 
exclude 
character vector,
the name(s) of variable(s) to be excluded.
Default 
exclude_pattern 
(optional) character scalar as regex (regular expression), the pattern of the names of the variable(s) to be excluded. 
include 
character vector,
the name(s) of variable(s) to be included.
Default 
include_pattern 
(optional) character scalar as regex (regular expression), the pattern of the names of the variable(s) to be included. 
paired 
logical scalar, whether to perform paired test (default 
robust 
logical scalar.
If 
overall 
logical scalar.
If 
compare 
logical scalar.
If 
pairwise 
integer scalar,
minimum number of groups where pairwise comparisons need to be performed.
Default 
Details
A demographic table with simple summary statistics, with optional comparison(s) over one or more groups, is created.
numeric variables are summarized in means, standard deviations, medians, interquartileranges (IQR),
skewness, p
value of ShapiroWilk normality test and ranges.
If group
is specified, they are compared using twosample t.test,
wilcox.test (Wilcoxon / MannWhitney), oneway aov (ANOVA) and/or
kruskal.test (KruskalWallis).
logical and factor variables are summarized in counts and percentages.
If group
is specified, they are compared using prop.test (chisquared)
and/or fisher.test (Fisher's exact).
Value
Function DemographicTable returns an object of S3 class 'DemographicTable'
,
which inherits from matrix.
Examples
DemographicTable(esoph)
DemographicTable(ToothGrowth, groups = 'supp', include = 'len')
DemographicTable(ToothGrowth, groups = 'supp', include = 'len', paired = TRUE)
DemographicTable(ToothGrowth, groups = 'supp', include = 'len', compare = FALSE)
DemographicTable(warpbreaks, groups = c('wool', 'tension'))
DemographicTable(mtcars, groups = c('vs', 'am'), include = c('mpg', 'cyl', 'disp'))
# with missing value
DemographicTable(airquality, groups = 'Month', exclude = 'Day')
DemographicTable(MASS::survey, groups = 'Smoke', keep_missing_group = FALSE)
DemographicTable(MASS::survey, groups = 'Smoke', keep_missing_group = FALSE, useNA = 'always')
# write to Word file
library(flextable)
library(officer)
x = read_docx() > body_add_flextable(value = as_flextable(DemographicTable(esoph)))
(out = file.path(tempdir(), 'demotable.docx'))
print(x, target = out)
# system(paste('open', out)) # works on Mac & Windows, but requires Microsoft Word
file.remove(out)