使用expss包的行标签

时间:2018-06-21 09:02:37

标签: r expss

是否可以在每一行上重复标签,以使以下代码的输出看起来类似:enter image description here

代替: enter image description here

其中所需的输出应在每行而不是仅第一行包含标签。

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 (lb/1000)",
                      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 %>% 
     tab_cells(cyl, gear) %>% 
     tab_prepend_all %>% 
     tab_cols(total(), vs) %>% 
     tab_stat_cpct() %>% 
     tab_pivot()

1 个答案:

答案 0 :(得分:0)

如果您使用as.datatable_widget函数进行输出,那么会有一个特殊的参数repeat_row_labels。将其设置为TRUE以获得所需的结果。如果您使用的是split_columns,则还有另一个自变量命名为remove_repeated的自变量。将其设置为FALSE以重复行标签。