简体   繁体   English

如何删除 expss 表中的 row_labels 文本?

[英]How do you remove the row_labels text in an expss table?

I like to pipe my expss tables into kable to get access to some additional formatting options.我喜欢将我的expss表 pipe 转换为kable以访问一些额外的格式选项。 That sometimes requires some tweaking, and I'm looking for a tweak here to get rid of the row_labels text in the first column of the header in the example below.这有时需要一些调整,我正在这里寻找一个调整来摆脱下面示例中 header 第一列中的row_labels文本。

Simple reprex:简单的代表:

df <- data.frame(x=rbinom(100,1,0.5), y=rnorm(100,1,0.6),
                 z=rnorm(100,1,0.2), grp = rep(1:5,20))
var_lab(df$grp) = ""
df %>%
  tab_cells(x,y,z) %>%
  tab_cols(grp) %>%
  tab_stat_mean (label = "") %>%
  tab_pivot %>%
  kable(caption= "Title",
        digits = c(0,rep(3,5))) %>%
  kable_styling(full_width=F, position="center", 
                bootstrap_options = c("striped"))%>%
  add_header_above(c("", "Group" = 5))

Generates this:生成这个:

html表格

Thanks!谢谢!

It's better to use 'htmlTable' or 'huxtable' for output expss tables. output expss 表最好使用“htmlTable”或“huxtable”。 It is because they are both support complex multilevel and multinested headers.这是因为它们都支持复杂的多级和多嵌套标题。 However, if you want to use 'kable' you can set first column name to empty string just after 'tab_pivot':但是,如果您想使用“kable”,您可以在“tab_pivot”之后将第一列名称设置为空字符串:

library(expss)
library(knitr)
library(kableExtra)

# function which remove first column name
remove_first_name = function(x){
    setNames(x, c("", names(x)[-1]))
}


df <- data.frame(x=rbinom(100,1,0.5), y=rnorm(100,1,0.6),
                 z=rnorm(100,1,0.2), grp = rep(1:5,20))
var_lab(df$grp) = ""
df %>%
    tab_cells(x,y,z) %>%
    tab_cols(grp) %>%
    tab_stat_mean (label = "") %>%
    tab_pivot %>%
    remove_first_name %>%  # remove 'row_labels'
    kable(caption= "Title",
          digits = c(0,rep(3,5))) %>%
    kable_styling(full_width=F, position="center", 
                  bootstrap_options = c("striped"))%>%
    add_header_above(c("", "Group" = 5)) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM