2

我想生成一个带有排序频率数据的 expss 表,以下面的在线示例为例

library(expss)
data(mtcars)
mtcars = apply_labels(mtcars,
                      mpg = "Miles/(US) gallon",
                      cyl = "Number of cylinders",
                      disp = "Displacement (cu.in.)",
                      hp = "Gross horsepower",
                      drat = "Rear axle ratio",
                      wt = "Weight (1000 lbs)",
                      qsec = "1/4 mile time",
                      vs = "Engine",
                      vs = c("V-engine" = 0,
                             "Straight engine" = 1),
                      am = "Transmission",
                      am = c("Automatic" = 0,
                             "Manual"=1),
                      gear = "Number of forward gears",
                      carb = "Number of carburetors"
)
mtcars %>% calc_cro_cpct(cyl, list(total(), am, vs))

这导致了这个输出: 在此处输入图像描述

但是,我希望能够通过“#Total cases”行的降序值对 Table1 进行排序。我能够对列使用 tab_sort_desc 命令,但是每当我在此命令中选择一行时,我都会收到“错误:未找到名称:...”

可以将任何命令添加到上面的代码中以按值对行进行排序?

4

1 回答 1

0

似乎最简单的方法是表格转置:

mtcars %>% 
    calc_cro_cpct(cyl, list(total(), am, vs)) %>% 
    tab_transpose() %>% # transpose
    tab_sort_desc(., ncol(.)) %>% # sort by total
    tab_transpose() # reverse transposition
于 2018-07-10T21:02:13.413 回答