Using the TableOne instructions from (https://cran.r-project.org/web/packages/tableone/vignettes/introduction.html) on the palmerpenguins package.
data(penguins)
CreateTableOne(data = penguins)
Overall
n 344
species (%)
Adelie 152 (44.2)
Chinstrap 68 (19.8)
Gentoo 124 (36.0)
island (%)
Biscoe 168 (48.8)
Dream 124 (36.0)
Torgersen 52 (15.1)
bill_length_mm (mean (SD)) 43.92 (5.46)
bill_depth_mm (mean (SD)) 17.15 (1.97)
flipper_length_mm (mean (SD)) 200.92 (14.06)
body_mass_g (mean (SD)) 4201.75 (801.95)
sex = male (%) 168 (50.5)
year (mean (SD)) 2008.03 (0.82)
c("species", "island", "bill_length_mm", "bill_depth_mm", "flipper_length_mm",
"body_mass_g", "sex", "year")
myVars <- c("species", "island", "bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g", "sex", "year")
catVars <- c("species", "island", "sex", "year")
tab2 <- CreateTableOne(vars = myVars, data = penguins, factorVars = catVars)
level Overall
n 344
species (%) Adelie 152 (44.2)
Chinstrap 68 (19.8)
Gentoo 124 (36.0)
island (%) Biscoe 168 (48.8)
Dream 124 (36.0)
Torgersen 52 (15.1)
bill_length_mm (mean (SD)) 43.92 (5.46)
bill_depth_mm (mean (SD)) 17.15 (1.97)
flipper_length_mm (mean (SD)) 200.92 (14.06)
body_mass_g (mean (SD)) 4,201.75 (801.95)
sex (%) female 165 (49.5)
male 168 (50.5)
year (%) 2007 110 (32.0)
2008 114 (33.1)
2009 120 (34.9)
summary(tab2)
### Summary of continuous variables ###
strata: Overall
n miss p.miss mean sd median p25 p75 min max
bill_length_mm 344 2 0.6 44 5 44 39 48 32 60
bill_depth_mm 344 2 0.6 17 2 17 16 19 13 22
flipper_length_mm 344 2 0.6 201 14 197 190 213 172 231
body_mass_g 344 2 0.6 4202 802 4050 3550 4750 2700 6300
skew kurt
bill_length_mm 0.05 -0.9
bill_depth_mm -0.14 -0.9
flipper_length_mm 0.35 -1.0
body_mass_g 0.47 -0.7
=======================================================================================
### Summary of categorical variables ###
strata: Overall
var n miss p.miss level freq percent cum.percent
species 344 0 0.0 Adelie 152 44.2 44.2
Chinstrap 68 19.8 64.0
Gentoo 124 36.0 100.0
island 344 0 0.0 Biscoe 168 48.8 48.8
Dream 124 36.0 84.9
Torgersen 52 15.1 100.0
sex 344 11 3.2 female 165 49.5 49.5
male 168 50.5 100.0
year 344 0 0.0 2007 110 32.0 32.0
2008 114 33.1 65.1
2009 120 34.9 100.0
tab3 <- CreateTableOne(vars = myVars, strata = "species", data = penguins, factorVars = catVars)
print(tab3, formatOptions = list(big.mark = ","))
Stratified by species
Adelie Chinstrap
n 152 68
species (%)
Adelie 152 (100.0) 0 ( 0.0)
Chinstrap 0 ( 0.0) 68 (100.0)
Gentoo 0 ( 0.0) 0 ( 0.0)
island (%)
Biscoe 44 ( 28.9) 0 ( 0.0)
Dream 56 ( 36.8) 68 (100.0)
Torgersen 52 ( 34.2) 0 ( 0.0)
bill_length_mm (mean (SD)) 38.79 (2.66) 48.83 (3.34)
bill_depth_mm (mean (SD)) 18.35 (1.22) 18.42 (1.14)
flipper_length_mm (mean (SD)) 189.95 (6.54) 195.82 (7.13)
body_mass_g (mean (SD)) 3,700.66 (458.57) 3,733.09 (384.34)
sex = male (%) 73 ( 50.0) 34 ( 50.0)
year (%)
2007 50 ( 32.9) 26 ( 38.2)
2008 50 ( 32.9) 18 ( 26.5)
2009 52 ( 34.2) 24 ( 35.3)
Stratified by species
Gentoo p test
n 124
species (%) <0.001
Adelie 0 ( 0.0)
Chinstrap 0 ( 0.0)
Gentoo 124 (100.0)
island (%) <0.001
Biscoe 124 (100.0)
Dream 0 ( 0.0)
Torgersen 0 ( 0.0)
bill_length_mm (mean (SD)) 47.50 (3.08) <0.001
bill_depth_mm (mean (SD)) 14.98 (0.98) <0.001
flipper_length_mm (mean (SD)) 217.19 (6.48) <0.001
body_mass_g (mean (SD)) 5,076.02 (504.12) <0.001
sex = male (%) 61 ( 51.3) 0.976
year (%) 0.522
2007 34 ( 27.4)
2008 46 ( 37.1)
2009 44 ( 35.5)
print(tab3, exact = "year", smd = TRUE)
Stratified by species
Adelie Chinstrap
n 152 68
species (%)
Adelie 152 (100.0) 0 ( 0.0)
Chinstrap 0 ( 0.0) 68 (100.0)
Gentoo 0 ( 0.0) 0 ( 0.0)
island (%)
Biscoe 44 ( 28.9) 0 ( 0.0)
Dream 56 ( 36.8) 68 (100.0)
Torgersen 52 ( 34.2) 0 ( 0.0)
bill_length_mm (mean (SD)) 38.79 (2.66) 48.83 (3.34)
bill_depth_mm (mean (SD)) 18.35 (1.22) 18.42 (1.14)
flipper_length_mm (mean (SD)) 189.95 (6.54) 195.82 (7.13)
body_mass_g (mean (SD)) 3700.66 (458.57) 3733.09 (384.34)
sex = male (%) 73 ( 50.0) 34 ( 50.0)
year (%)
2007 50 ( 32.9) 26 ( 38.2)
2008 50 ( 32.9) 18 ( 26.5)
2009 52 ( 34.2) 24 ( 35.3)
Stratified by species
Gentoo p test SMD
n 124
species (%) <0.001 NaN
Adelie 0 ( 0.0)
Chinstrap 0 ( 0.0)
Gentoo 124 (100.0)
island (%) <0.001 NaN
Biscoe 124 (100.0)
Dream 0 ( 0.0)
Torgersen 0 ( 0.0)
bill_length_mm (mean (SD)) 47.50 (3.08) <0.001 2.255
bill_depth_mm (mean (SD)) 14.98 (0.98) <0.001 2.116
flipper_length_mm (mean (SD)) 217.19 (6.48) <0.001 2.725
body_mass_g (mean (SD)) 5076.02 (504.12) <0.001 1.976
sex = male (%) 61 ( 51.3) 0.976 0.017
year (%) 0.522 exact 0.181
2007 34 ( 27.4)
2008 46 ( 37.1)
2009 44 ( 35.5)
tab3$CatTable
Stratified by species
Adelie Chinstrap Gentoo p test
n 152 68 124
species (%) <0.001
Adelie 152 (100.0) 0 ( 0.0) 0 ( 0.0)
Chinstrap 0 ( 0.0) 68 (100.0) 0 ( 0.0)
Gentoo 0 ( 0.0) 0 ( 0.0) 124 (100.0)
island (%) <0.001
Biscoe 44 ( 28.9) 0 ( 0.0) 124 (100.0)
Dream 56 ( 36.8) 68 (100.0) 0 ( 0.0)
Torgersen 52 ( 34.2) 0 ( 0.0) 0 ( 0.0)
sex = male (%) 73 ( 50.0) 34 ( 50.0) 61 ( 51.3) 0.976
year (%) 0.522
2007 50 ( 32.9) 26 ( 38.2) 34 ( 27.4)
2008 50 ( 32.9) 18 ( 26.5) 46 ( 37.1)
2009 52 ( 34.2) 24 ( 35.3) 44 ( 35.5)
print(tab3$ContTable)
Stratified by species
Adelie Chinstrap
n 152 68
bill_length_mm (mean (SD)) 38.79 (2.66) 48.83 (3.34)
bill_depth_mm (mean (SD)) 18.35 (1.22) 18.42 (1.14)
flipper_length_mm (mean (SD)) 189.95 (6.54) 195.82 (7.13)
body_mass_g (mean (SD)) 3700.66 (458.57) 3733.09 (384.34)
Stratified by species
Gentoo p test
n 124
bill_length_mm (mean (SD)) 47.50 (3.08) <0.001
bill_depth_mm (mean (SD)) 14.98 (0.98) <0.001
flipper_length_mm (mean (SD)) 217.19 (6.48) <0.001
body_mass_g (mean (SD)) 5076.02 (504.12) <0.001