The epitable package creates a frequency and percentage table commonly used in epidemiological papers. It is a wrapper for the htmlTables-package.
head(example_data)
## # A tibble: 6 x 10
## carat cut color clarity depth table price x y z
## <dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
## 1 0.23 Ideal E SI2 61.5 55 326 3.95 3.98 2.43
## 2 0.21 Premium E SI1 59.8 61 326 3.89 3.84 2.31
## 3 0.23 Good E VS1 56.9 65 327 4.05 4.07 2.31
## 4 0.29 Premium I VS2 62.4 58 334 4.20 4.23 2.63
## 5 0.31 Good J SI2 63.3 58 335 4.34 4.35 2.75
## 6 0.24 Very Good J VVS2 62.8 57 336 3.94 3.96 2.48
Counts and frequencies of the variables color
and clarity
grouped by cut
is obtained below:
freq_by(dataset = example_data, var_vector = c("color", "clarity"), by_group = "cut" )
Total | Fair | Good | Very Good | Premium | Ideal | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
n | (%) | n | (%) | n | (%) | n | (%) | n | (%) | n | (%) | |||||||
Color | ||||||||||||||||||
D | 6 775 | 13% | 163 | 10% | 662 | 13% | 1 513 | 13% | 1 603 | 12% | 2 834 | 13% | ||||||
E | 9 797 | 18% | 224 | 14% | 933 | 19% | 2 400 | 20% | 2 337 | 17% | 3 903 | 18% | ||||||
F | 9 542 | 18% | 312 | 19% | 909 | 19% | 2 164 | 18% | 2 331 | 17% | 3 826 | 18% | ||||||
G | 11 292 | 21% | 314 | 20% | 871 | 18% | 2 299 | 19% | 2 924 | 21% | 4 884 | 23% | ||||||
H | 8 304 | 15% | 303 | 19% | 702 | 14% | 1 824 | 15% | 2 360 | 17% | 3 115 | 14% | ||||||
I | 5 422 | 10% | 175 | 11% | 522 | 11% | 1 204 | 10% | 1 428 | 10% | 2 093 | 10% | ||||||
J | 2 808 | 5% | 119 | 7% | 307 | 6% | 678 | 6% | 808 | 6% | 896 | 4% | ||||||
Clarity | ||||||||||||||||||
I1 | 741 | 1% | 210 | 13% | 96 | 2% | 84 | 1% | 205 | 1% | 146 | 1% | ||||||
SI2 | 9 194 | 17% | 466 | 29% | 1 081 | 22% | 2 100 | 17% | 2 949 | 21% | 2 598 | 12% | ||||||
SI1 | 13 065 | 24% | 408 | 25% | 1 560 | 32% | 3 240 | 27% | 3 575 | 26% | 4 282 | 20% | ||||||
VS2 | 12 258 | 23% | 261 | 16% | 978 | 20% | 2 591 | 21% | 3 357 | 24% | 5 071 | 24% | ||||||
VS1 | 8 171 | 15% | 170 | 11% | 648 | 13% | 1 775 | 15% | 1 989 | 14% | 3 589 | 17% | ||||||
VVS2 | 5 066 | 9% | 69 | 4% | 286 | 6% | 1 235 | 10% | 870 | 6% | 2 606 | 12% | ||||||
VVS1 | 3 655 | 7% | 17 | 1% | 186 | 4% | 789 | 7% | 616 | 4% | 2 047 | 9% | ||||||
IF | 1 790 | 3% | 9 | 1% | 71 | 1% | 268 | 2% | 230 | 2% | 1 212 | 6% |
The by_group
variable must be of class factor, to ensure correct order.
To do in a possible future:
by_group
sThe output is a HTML-table created by the htmlTable-package. The HTML-output looks best if no CSS is used.