0

我有一个基于 mtcars 数据集的表。在专栏中,我有变量引擎和变速器;在该行中,我有可变的柱面编号。我想要每行的箱子数或每个气缸数的箱子数,而不是 100

多个横幅非常重要

library(expss)
data(mtcars)
mtcars %>% 
    tab_cells(cyl) %>% 
    tab_cols(vs,total(),am,total("u_cases"),vs,total()) %>% 
    tab_total_row_position("below") %>% 
    tab_total_statistic("u_rpct")%>%
    tab_stat_rpct() %>% 
    tab_pivot()
4

1 回答 1

0

如果我正确理解您需要什么:

mtcars %>% 
    tab_cells(cyl) %>% 
    tab_total_row_position("below") %>% 
    tab_total_statistic("u_rpct")%>%
    tab_cols(vs) %>% 
    tab_stat_rpct() %>% 
    tab_cols(total(vs)) %>% 
    tab_stat_cases() %>% 
    tab_cols(am) %>% 
    tab_stat_rpct() %>% 
    tab_cols(total(am)) %>% 
    tab_stat_cases() %>% 
    tab_pivot(stat_position = "outside_columns")

# |     |             |    vs |      | #Total |   am |      | #Total |
# |     |             |     0 |    1 |        |    0 |    1 |        |
# | --- | ----------- | ----- | ---- | ------ | ---- | ---- | ------ |
# | cyl |           4 |   9.1 | 90.9 |     11 | 27.3 | 72.7 |     11 |
# |     |           6 |  42.9 | 57.1 |      7 | 57.1 | 42.9 |      7 |
# |     |           8 | 100.0 |      |     14 | 85.7 | 14.3 |     14 |
# |     | #Total rpct |  56.2 | 43.8 |    100 | 59.4 | 40.6 |    100 |
于 2019-10-11T17:03:00.843 回答