【问题标题】:Sorting expss output table排序 expss 输出表
【发布时间】:2018-12-18 11:48:01
【问题描述】:

我想生成一个带有排序频率数据的 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 命令,但是每当我在此命令中选择一行时,我都会收到“错误:未找到名称:...”

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

【问题讨论】:

    标签: r sorting spss expss


    【解决方案1】:

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

    mtcars %>% 
        calc_cro_cpct(cyl, list(total(), am, vs)) %>% 
        tab_transpose() %>% # transpose
        tab_sort_desc(., ncol(.)) %>% # sort by total
        tab_transpose() # reverse transposition
    

    【讨论】:

    • 谢谢,很高兴知道这一点。由于我是编码初学者,请原谅我的幼稚问题,但“。”默认为总计?可以用频率排序的特定行替换它吗?
    • @gfa2001 '.'表示先前的结果(%>% 的左侧)。所以ncol(.) 表示表格的最后一列是“#Total cases”。您可以将ncol(.) 替换为所需的列号。
    猜你喜欢
    • 2022-10-20
    • 1970-01-01
    • 2016-03-18
    • 1970-01-01
    • 2015-12-04
    • 2020-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多