Recommendations for Using summarytools With Rmarkdown

Dominic Comtois

2018-02-11

This document uses theme rmarkdown::html_vignette.

Below are examples using recommended styles for rmarkdown rendering. Available styles are:

Jump to…


freq()

freq() is best used with default or rmarkdown styles. HTML rendering is not recommended.

Default (simple) Style

freq(tobacco$gender)

Frequencies
gender
Data frame: tobacco
Type: Factor (unordered)

Freq % Valid % Valid Cum. % Total % Total Cum.
F 489 50.00 50.00 48.90 48.90
M 489 50.00 100.00 48.90 97.80
22 2.20 100.00
Total 1000 100.00 100.00 100.00 100.00

Default (simple) Style with plain.ascii = FALSE

freq(tobacco$gender, plain.ascii = FALSE)

Frequencies

gender
Data frame: tobacco
Type: Factor (unordered)

  Freq % Valid % Valid Cum. % Total % Total Cum.
F 489 50.00 50.00 48.90 48.90
M 489 50.00 100.00 48.90 97.80
<NA> 22 2.20 100.00
Total 1000 100.00 100.00 100.00 100.00

Rmarkdown Style

freq(tobacco$gender, style = 'rmarkdown')

Frequencies

gender
Data frame: tobacco
Type: Factor (unordered)

  Freq % Valid % Valid Cum. % Total % Total Cum.
F 489 50.00 50.00 48.90 48.90
M 489 50.00 100.00 48.90 97.80
<NA> 22 2.20 100.00
Total 1000 100.00 100.00 100.00 100.00
freq(tobacco$gender, style = 'rmarkdown', omit.headings = TRUE)
  Freq % Valid % Valid Cum. % Total % Total Cum.
F 489 50.00 50.00 48.90 48.90
M 489 50.00 100.00 48.90 97.80
<NA> 22 2.20 100.00
Total 1000 100.00 100.00 100.00 100.00

Back to top

descr()

descr() is best used with default or rmarkdown styles. HTML rendering is also supported.

Default Style

descr(tobacco)
Non-numerical variable(s) ignored: gender, age.gr, smoker, diseased, disease

Descriptive Statistics
Data Frame: tobacco
N: 1000

age BMI cigs.per.day samp.wgts
Mean 49.60 25.73 6.78 1.00
Std.Dev 18.29 4.49 11.88 0.08
Min 18.00 8.83 0.00 0.86
Median 50.00 25.62 0.00 1.04
Max 80.00 39.44 40.00 1.06
MAD 23.72 4.18 0.00 0.01
IQR 32.00 5.72 11.00 0.19
CV 2.71 5.73 0.57 11.92
Skewness -0.04 0.02 1.54 -1.04
SE.Skewness 0.08 0.08 0.08 0.08
Kurtosis -1.26 0.26 0.90 -0.90
N.Valid 975.00 974.00 965.00 1000.00
Pct.Valid 97.50 97.40 96.50 100.00

Default Style with plain.ascii = FALSE

descr(tobacco, plain.ascii = FALSE)
Non-numerical variable(s) ignored: gender, age.gr, smoker, diseased, disease

Descriptive Statistics

Data Frame: tobacco
N: 1000

  age BMI cigs.per.day samp.wgts
Mean 49.60 25.73 6.78 1.00
Std.Dev 18.29 4.49 11.88 0.08
Min 18.00 8.83 0.00 0.86
Median 50.00 25.62 0.00 1.04
Max 80.00 39.44 40.00 1.06
MAD 23.72 4.18 0.00 0.01
IQR 32.00 5.72 11.00 0.19
CV 2.71 5.73 0.57 11.92
Skewness -0.04 0.02 1.54 -1.04
SE.Skewness 0.08 0.08 0.08 0.08
Kurtosis -1.26 0.26 0.90 -0.90
N.Valid 975.00 974.00 965.00 1000.00
Pct.Valid 97.50 97.40 96.50 100.00
descr(tobacco$BMI, plain.ascii = FALSE)

Descriptive Statistics

BMI
Data Frame: tobacco
N: 1000

  BMI
Mean 25.73
Std.Dev 4.49
Min 8.83
Median 25.62
Max 39.44
MAD 4.18
IQR 5.72
CV 5.73
Skewness 0.02
SE.Skewness 0.08
Kurtosis 0.26
N.Valid 974.00
Pct.Valid 97.40

Rmarkdown Style

descr(tobacco, style = 'rmarkdown')
Non-numerical variable(s) ignored: gender, age.gr, smoker, diseased, disease

Descriptive Statistics

Data Frame: tobacco
N: 1000

  age BMI cigs.per.day samp.wgts
Mean 49.60 25.73 6.78 1.00
Std.Dev 18.29 4.49 11.88 0.08
Min 18.00 8.83 0.00 0.86
Median 50.00 25.62 0.00 1.04
Max 80.00 39.44 40.00 1.06
MAD 23.72 4.18 0.00 0.01
IQR 32.00 5.72 11.00 0.19
CV 2.71 5.73 0.57 11.92
Skewness -0.04 0.02 1.54 -1.04
SE.Skewness 0.08 0.08 0.08 0.08
Kurtosis -1.26 0.26 0.90 -0.90
N.Valid 975.00 974.00 965.00 1000.00
Pct.Valid 97.50 97.40 96.50 100.00
descr(tobacco$BMI, style = 'rmarkdown')

Descriptive Statistics

BMI
Data Frame: tobacco
N: 1000

  BMI
Mean 25.73
Std.Dev 4.49
Min 8.83
Median 25.62
Max 39.44
MAD 4.18
IQR 5.72
CV 5.73
Skewness 0.02
SE.Skewness 0.08
Kurtosis 0.26
N.Valid 974.00
Pct.Valid 97.40
descr(tobacco$BMI, style = 'rmarkdown', omit.headings = TRUE)
  BMI
Mean 25.73
Std.Dev 4.49
Min 8.83
Median 25.62
Max 39.44
MAD 4.18
IQR 5.72
CV 5.73
Skewness 0.02
SE.Skewness 0.08
Kurtosis 0.26
N.Valid 974.00
Pct.Valid 97.40

HTML Render

print(descr(tobacco), method = 'render')
Non-numerical variable(s) ignored: gender, age.gr, smoker, diseased, disease

Descriptive Statistics

Data Frame: tobacco
N: 1000
age BMI cigs.per.day samp.wgts
Mean 49.60 25.73 6.78 1.00
Std.Dev 18.29 4.49 11.88 0.08
Min 18.00 8.83 0.00 0.86
Median 50.00 25.62 0.00 1.04
Max 80.00 39.44 40.00 1.06
MAD 23.72 4.18 0.00 0.01
IQR 32.00 5.72 11.00 0.19
CV 2.71 5.73 0.57 11.92
Skewness -0.04 0.02 1.54 -1.04
SE.Skewness 0.08 0.08 0.08 0.08
Kurtosis -1.26 0.26 0.90 -0.90
N.Valid 975 974 965 1000
Pct.Valid 97.50 97.40 96.50 100.00

Generated by summarytools package version 0.8.2 (R version 3.4.3)
2018-02-11

print(descr(tobacco$BMI), method = 'render')

Descriptive Statistics

BMI

Data Frame: tobacco
N: 1000
BMI
Mean 25.73
Std.Dev 4.49
Min 8.83
Median 25.62
Max 39.44
MAD 4.18
IQR 5.72
CV 5.73
Skewness 0.02
SE.Skewness 0.08
Kurtosis 0.26
N.Valid 974
Pct.Valid 97.40

Generated by summarytools package version 0.8.2 (R version 3.4.3)
2018-02-11

print(descr(tobacco, omit.headings = TRUE), method = 'render')
Non-numerical variable(s) ignored: gender, age.gr, smoker, diseased, disease
age BMI cigs.per.day samp.wgts
Mean 49.60 25.73 6.78 1.00
Std.Dev 18.29 4.49 11.88 0.08
Min 18.00 8.83 0.00 0.86
Median 50.00 25.62 0.00 1.04
Max 80.00 39.44 40.00 1.06
MAD 23.72 4.18 0.00 0.01
IQR 32.00 5.72 11.00 0.19
CV 2.71 5.73 0.57 11.92
Skewness -0.04 0.02 1.54 -1.04
SE.Skewness 0.08 0.08 0.08 0.08
Kurtosis -1.26 0.26 0.90 -0.90
N.Valid 975 974 965 1000
Pct.Valid 97.50 97.40 96.50 100.00

Generated by summarytools package version 0.8.2 (R version 3.4.3)
2018-02-11


Back to top

Ctable()

For best results, use HTML rendering.

print(ctable(tobacco$gender, tobacco$smoker), method = 'render')

Cross-Tabulation / Row proportions

gender * smoker

Data Frame: tobacco
smoker
gender Yes No Total
F 147  ( 30.1% ) 342  ( 69.9% )  489  ( 100.0% )
M 143  ( 29.2% ) 346  ( 70.8% )  489  ( 100.0% )
<NA>   8  ( 36.4% )  14  ( 63.6% )   22  ( 100.0% )
Total 298  ( 29.8% ) 702  ( 70.2% ) 1000  ( 100.0% )

Generated by summarytools package version 0.8.2 (R version 3.4.3)
2018-02-11

print(ctable(tobacco$gender, tobacco$smoker, omit.headings = TRUE), method = 'render')
smoker
gender Yes No Total
F 147  ( 30.1% ) 342  ( 69.9% )  489  ( 100.0% )
M 143  ( 29.2% ) 346  ( 70.8% )  489  ( 100.0% )
<NA>   8  ( 36.4% )  14  ( 63.6% )   22  ( 100.0% )
Total 298  ( 29.8% ) 702  ( 70.2% ) 1000  ( 100.0% )

Generated by summarytools package version 0.8.2 (R version 3.4.3)
2018-02-11


Back to top

dfSummary()

For best results, use grid style and set graph.col = FALSE.

Grid Style

dfSummary(tobacco, style = 'grid', plain.ascii = FALSE, graph.col = FALSE)

Data Frame Summary

tobacco
N: 1000

No Variable Stats / Values Freqs (% of Valid) Valid Missing

1

gender [factor]

  1. F
  2. M

489 (50.0%)
489 (50.0%)

978 (97.8%)

22 (2.2%)

2

age [numeric]

mean (sd) : 49.6 (18.29)
min < med < max :
18 < 50 < 80
IQR (CV) : 32 (0.37)

63 distinct val.

975 (97.5%)

25 (2.5%)

3

age.gr [factor]

  1. 18-34
  2. 35-50
  3. 51-70
  4. 71 +

258 (26.5%)
241 (24.7%)
317 (32.5%)
159 (16.3%)

975 (97.5%)

25 (2.5%)

4

BMI [numeric]

mean (sd) : 25.73 (4.49)
min < med < max :
8.83 < 25.62 < 39.44
IQR (CV) : 5.72 (0.17)

974 distinct val.

974 (97.4%)

26 (2.6%)

5

smoker [factor]

  1. Yes
  2. No

298 (29.8%)
702 (70.2%)

1000 (100%)

0 (0%)

6

cigs.per.day [numeric]

mean (sd) : 6.78 (11.88)
min < med < max :
0 < 0 < 40
IQR (CV) : 11 (1.75)

37 distinct val.

965 (96.5%)

35 (3.5%)

7

diseased [factor]

  1. Yes
  2. No

224 (22.4%)
776 (77.6%)

1000 (100%)

0 (0%)

8

disease [character]

  1. Hypertension
  2. Cancer
  3. Cholesterol
  4. Heart
  5. Pulmonary
  6. Musculoskeletal
  7. Diabetes
  8. Hearing
  9. Digestive
  10. Hypotension
    [ 3 others ]

36 (16.2%)
34 (15.3%)
21 ( 9.5%)
20 ( 9.0%)
20 ( 9.0%)
19 ( 8.6%)
14 ( 6.3%)
14 ( 6.3%)
12 ( 5.4%)
11 ( 5.0%)
21 ( 9.4%)

222 (22.2%)

778 (77.8%)

9

samp.wgts [numeric]

mean (sd) : 1 (0.08)
min < med < max :
0.86 < 1.04 < 1.06
IQR (CV) : 0.19 (0.08)

0.86!: 267 (26.7%)
1.04!: 249 (24.9%)
1.05!: 324 (32.4%)
1.06!: 160 (16.0%)
! rounded

1000 (100%)

0 (0%)

dfSummary(tobacco, style = 'grid', plain.ascii = FALSE, graph.col = FALSE, omit.headings = TRUE)
No Variable Stats / Values Freqs (% of Valid) Valid Missing

1

gender [factor]

  1. F
  2. M

489 (50.0%)
489 (50.0%)

978 (97.8%)

22 (2.2%)

2

age [numeric]

mean (sd) : 49.6 (18.29)
min < med < max :
18 < 50 < 80
IQR (CV) : 32 (0.37)

63 distinct val.

975 (97.5%)

25 (2.5%)

3

age.gr [factor]

  1. 18-34
  2. 35-50
  3. 51-70
  4. 71 +

258 (26.5%)
241 (24.7%)
317 (32.5%)
159 (16.3%)

975 (97.5%)

25 (2.5%)

4

BMI [numeric]

mean (sd) : 25.73 (4.49)
min < med < max :
8.83 < 25.62 < 39.44
IQR (CV) : 5.72 (0.17)

974 distinct val.

974 (97.4%)

26 (2.6%)

5

smoker [factor]

  1. Yes
  2. No

298 (29.8%)
702 (70.2%)

1000 (100%)

0 (0%)

6

cigs.per.day [numeric]

mean (sd) : 6.78 (11.88)
min < med < max :
0 < 0 < 40
IQR (CV) : 11 (1.75)

37 distinct val.

965 (96.5%)

35 (3.5%)

7

diseased [factor]

  1. Yes
  2. No

224 (22.4%)
776 (77.6%)

1000 (100%)

0 (0%)

8

disease [character]

  1. Hypertension
  2. Cancer
  3. Cholesterol
  4. Heart
  5. Pulmonary
  6. Musculoskeletal
  7. Diabetes
  8. Hearing
  9. Digestive
  10. Hypotension
    [ 3 others ]

36 (16.2%)
34 (15.3%)
21 ( 9.5%)
20 ( 9.0%)
20 ( 9.0%)
19 ( 8.6%)
14 ( 6.3%)
14 ( 6.3%)
12 ( 5.4%)
11 ( 5.0%)
21 ( 9.4%)

222 (22.2%)

778 (77.8%)

9

samp.wgts [numeric]

mean (sd) : 1 (0.08)
min < med < max :
0.86 < 1.04 < 1.06
IQR (CV) : 0.19 (0.08)

0.86!: 267 (26.7%)
1.04!: 249 (24.9%)
1.05!: 324 (32.4%)
1.06!: 160 (16.0%)
! rounded

1000 (100%)

0 (0%)

Back to top