0

我是 R 新手。我可以在表格中创建前 3 个和后 3 个框,但它像这样显示为“TRUE”和“FALSE”......

在此处输入图像描述

我使用的代码是...

library(expss)

X4607 %>%
tab_cells(qcs1a_SQ001, "Top 3 Box"=qcs1a_SQ001>7 & qcs1a_SQ001<11, "Bottom 3 Box"=qcs1a_SQ001<=2) %>%
tab_cols(total(), spcode) %>%
tab_stat_cpct() %>%
tab_last_sig_cpct() %>%
tab_pivot()

有没有办法让“TRUE”的数量出现在“前 3 个框”标签下,并摆脱“TRUE”和“FALSE”的显示。

4

1 回答 1

0

有一个特殊的功能subtotal

library(expss)

set.seed(123)
N = 100
X4607 = data.frame(
    spcode = sample(c("South", "North"), size = N, replace = TRUE),
    qcs1a_SQ001 = sample(c(1:10, 99), size = N, replace = TRUE)
    
    )

X4607 %>%
    tab_cells(subtotal(qcs1a_SQ001, "Bottom 3 Box" = 1:3, "Top 3 Box" = 7:10, position = "bottom")) %>%
    tab_cols(total(), spcode) %>%
    tab_stat_cpct() %>%
    tab_last_sig_cpct() %>%
    tab_pivot()

# |              | #Total | spcode |        |
# |              |        |  North |  South |
# |              |        |      A |      B |
# | ------------ | ------ | ------ | ------ |
# |            1 |    5.0 |    9.3 |  1.8   |
# |            2 |    5.0 |    4.7 |  5.3   |
# |            3 |    9.0 |    4.7 | 12.3   |
# |            4 |   11.0 |    7.0 | 14.0   |
# |            5 |    6.0 |    9.3 |  3.5   |
# |            6 |   10.0 |    2.3 | 15.8 A |
# |            7 |   13.0 |   16.3 | 10.5   |
# |            8 |   14.0 |   16.3 | 12.3   |
# |            9 |   10.0 |   11.6 |  8.8   |
# |           10 |   10.0 |    9.3 | 10.5   |
# |           99 |    7.0 |    9.3 |  5.3   |
# | Bottom 3 Box |   19.0 |   18.6 | 19.3   |
# |    Top 3 Box |   47.0 |   53.5 | 42.1   |
# | #Total cases |    100 |     43 |   57   |
于 2021-02-12T09:36:01.147 回答