r - 排序 expss 输出表
问题描述
我想生成一个带有排序频率数据的 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 命令,但是每当我在此命令中选择一行时,我都会收到“错误:未找到名称:...”
可以将任何命令添加到上面的代码中以按值对行进行排序?
解决方案
似乎最简单的方法是表格转置:
mtcars %>%
calc_cro_cpct(cyl, list(total(), am, vs)) %>%
tab_transpose() %>% # transpose
tab_sort_desc(., ncol(.)) %>% # sort by total
tab_transpose() # reverse transposition
推荐阅读
- javascript - 将显示在数据库中的值插入不起作用
- python - 如何在 Python 中打印/返回矩阵中所有值的总和?
- php - 为什么 Laravel throw_unless 会给出内部服务器错误?
- javascript - 为什么 Javascript 计算这个方程的方式与我的计算器不同?
- javascript - 我无法从 React 事件侦听器上的函数更改变量
- visual-studio - 在 .NET Core 项目中使用 T4 模板时遇到问题
- clang-format - clang-format:将结构初始化保持在一行
- python - requests.exceptions.SSLError 使用“请求”包
- r - 在 plot_ly 和 ggplot 中为图形添加复选框
- python - Appium - 使用可变输入值的 xpath 或定位器 - 蓝牙选择