utils::install.packages('DemographicTable')The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.
2026-09-25
utils::install.packages('DemographicTable')Examples in this vignette requires
library(DemographicTable)Users may remove the last pipe |> print() from all examples if they are using R interactively.
datasets::penguins |>
subset.data.frame(select = c('species', 'island', 'bill_len')) |>
DemographicTable(data.name = 'datasets::penguins') |>
print()
| datasets::penguins |
|---|---|
n=344 | |
bill_len. | n*=342 |
species: n (%). |
|
island: n (%). |
|
| n=344 |
datasets::penguins |
Color of each individual group is determined by scales::pal_hue(), which is the default color pallete used in package ggplot2.
penguins by sex
datasets::penguins |>
subset.data.frame(select = c('sex', 'species', 'bill_dep')) |>
DemographicTable(by = ~ sex, data.name = 'datasets::penguins') |>
print()
| datasets::penguins | |||
|---|---|---|---|---|
n=344 | sex | |||
female | male | Signif | ||
bill_dep. | n*=342 |
|
| 0.000★ |
sex: n (%). | n*=333 |
|
| ★ 0.000 |
species: n (%). |
|
|
| 0.979 |
| n=344 | sex | ||
datasets::penguins | ||||
User may choose to hide the p-values with option compare = FALSE.
datasets::penguins |>
subset.data.frame(select = c('sex', 'species', 'bill_dep')) |>
DemographicTable(by = ~ sex, data.name = 'datasets::penguins', compare = FALSE) |>
print()
| datasets::penguins | ||
|---|---|---|---|
n=344 | sex | ||
female | male | ||
bill_dep. | n*=342 |
|
|
sex: n (%). | n*=333 |
|
|
species: n (%). |
|
|
|
| n=344 | sex | |
datasets::penguins | |||
datasets::penguins |>
subset.data.frame(select = c('sex', 'island', 'species', 'bill_dep')) |>
DemographicTable(by = ~ sex + island, data.name = 'datasets::penguins', compare = FALSE) |>
print()
| datasets::penguins | |||||
|---|---|---|---|---|---|---|
n=344 | sex | island | ||||
female | male | Biscoe | Dream | Torgersen | ||
bill_dep. | n*=342 |
|
| n*=167 |
| n*=51 |
sex: n (%). | n*=333 |
|
| n*=163 | n*=123 | n*=47 |
island: n (%). |
|
|
|
|
|
|
species: n (%). |
|
|
|
|
|
|
| n=344 | sex | island | |||
datasets::penguins | ||||||
DemographicTablesmale = datasets::penguins |>
subset(subset = (sex == 'male'), select = c('island', 'species', 'bill_dep')) |>
DemographicTable(by = ~ island, data.name = 'Male Penguins', compare = FALSE)female = datasets::penguins |>
subset(subset = (sex == 'female'), select = c('island', 'species', 'bill_dep')) |>
DemographicTable(by = ~ island, data.name = 'Female Penguins', compare = FALSE)c(male, female) |>
print()
| Male Penguins | Female Penguins | ||||||
|---|---|---|---|---|---|---|---|---|
n=168 | island | n=165 | island | |||||
Biscoe | Dream | Torgersen | Biscoe | Dream | Torgersen | |||
bill_dep. |
|
|
|
|
|
|
|
|
island: n (%). |
|
|
|
|
|
|
|
|
species: n (%). |
|
|
|
|
|
|
|
|
| n=168 | island | n=165 | island | ||||
Male Penguins | Female Penguins | |||||||
Remove the “overall” column.
tb = datasets::penguins |>
subset.data.frame(select = c('sex', 'island', 'species', 'bill_dep')) |>
DemographicTable(by = ~ sex + island, data.name = 'datasets::penguins', compare = FALSE)
tb[-1L] |>
print()
| datasets::penguins | ||||
|---|---|---|---|---|---|
sex | island | ||||
female | male | Biscoe | Dream | Torgersen | |
bill_dep. |
|
| n*=167 |
| n*=51 |
sex: n (%). |
|
| n*=163 | n*=123 | n*=47 |
island: n (%). |
|
|
|
|
|
species: n (%). |
|
|
|
|
|
| sex | island | |||
datasets::penguins | |||||
c(male, female)[2:4] |>
print()
| Male Penguins | Female Penguins | |||||
|---|---|---|---|---|---|---|---|
island | n=165 | island | |||||
Biscoe | Dream | Torgersen | Biscoe | Dream | Torgersen | ||
bill_dep. |
|
|
|
|
|
|
|
island: n (%). |
|
|
|
|
|
|
|
species: n (%). |
|
|
|
|
|
|
|
| island | n=165 | island | ||||
Male Penguins | Female Penguins | ||||||
c(male, female)[c(2L, 4L)] |>
print()
| Male Penguins | Female Penguins | ||||
|---|---|---|---|---|---|---|
island | ||||||
Biscoe | Dream | Torgersen | Biscoe | Dream | Torgersen | |
bill_dep. |
|
|
|
|
|
|
island: n (%). |
|
|
|
|
|
|
species: n (%). |
|
|
|
|
|
|
| island | |||||
Male Penguins | Female Penguins | |||||
See Listing 1.
logical valuesUsing logical values is discouraged (Listing 2), as this practice is proved confusing to scientists without a strong data background.
logical values is discouraged
datasets::mtcars |>
within.data.frame(expr = {
vs_straight = as.logical(vs)
am_manual = as.logical(am)
}) |>
subset.data.frame(select = c('am_manual', 'drat', 'vs_straight')) |>
DemographicTable(by = ~ am_manual, data.name = 'mtcars') |>
print()
| mtcars | |||
|---|---|---|---|---|
n=32 | am_manual | |||
FALSE | TRUE | Signif | ||
drat. |
|
|
| 0.000★ |
am_manual: n (%) | 13 (40.6%) | - | 13 (100.0%) | |
vs_straight: n (%) | 14 (43.8%) | 7 (36.8%) | 7 (53.8%) | 0.556 |
| n=32 | am_manual | ||
mtcars | ||||
Instead of using logical variables, we recommend using 2-level factors (Listing 3).
level factors
datasets::mtcars |>
within.data.frame(expr = {
vs = ifelse(vs, yes = 'Straight', no = 'V-shaped')
am = ifelse(am, yes = 'manual', no = 'automatic')
}) |>
subset.data.frame(select = c('am', 'drat', 'vs')) |>
DemographicTable(by = ~ am, data.name = 'mtcars') |>
print()
| mtcars | |||
|---|---|---|---|---|
n=32 | am | |||
automatic | manual | Signif | ||
drat. |
|
|
| 0.000★ |
am: n (%). |
|
|
| ★ 0.000 |
vs: n (%). |
|
|
| 0.473 |
| n=32 | am | ||
mtcars | ||||
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.