library(dplyr)
library(janitor)
mtcars %>% janitor::tabyl(am,vs)
am 0 1
0 12 7
1 6 7
library(flextable)
mtcars %>% janitor::tabyl(am,vs, percent = 'col') %>% flextable() %>% theme_tron()
am | 0 | 1 |
0 | 12 | 7 |
1 | 6 | 7 |
# Por linha
mtcars %>% janitor::tabyl(am,vs) %>%
adorn_percentages("row") %>%
adorn_pct_formatting(digits = 2) %>%
adorn_ns() %>% flextable() %>% theme_tron()
am | 0 | 1 |
0 | 63.16% (12) | 36.84% (7) |
1 | 46.15% (6) | 53.85% (7) |
# Por coluna
mtcars %>% janitor::tabyl(am,vs) %>%
adorn_percentages("col") %>%
adorn_pct_formatting(digits = 2) %>%
adorn_ns() %>%
flextable() %>% theme_tron()
am | 0 | 1 |
0 | 66.67% (12) | 50.00% (7) |
1 | 33.33% (6) | 50.00% (7) |
library(modelsummary)
# Por linha
datasummary_crosstab(am ~ vs, data = mtcars)
am | 0 | 1 | All | |
---|---|---|---|---|
0 | N | 12 | 7 | 19 |
% row | 63.2 | 36.8 | 100.0 | |
1 | N | 6 | 7 | 13 |
% row | 46.2 | 53.8 | 100.0 | |
All | N | 18 | 14 | 32 |
% row | 56.2 | 43.8 | 100.0 |
# Por coluna
datasummary_crosstab(am ~ vs,
statistic = 1 ~ Percent("col"),
data = mtcars)
am | 0 | 1 | |
---|---|---|---|
0 | % col | 66.7 | 50.0 |
1 | % col | 33.3 | 50.0 |
All | % col | 100.0 | 100.0 |