如何删除 expss table 中的 row_labels 文本?
How do you remove the row_labels text in an expss table?
我喜欢将我的 expss
表格通过管道传输到 kable
中以访问一些额外的格式设置选项。这有时需要一些调整,我正在寻找一个调整来摆脱示例中 header 第一列中的 row_labels 文本下面。
简单表示:
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))
生成这个:
谢谢!
输出expss表最好使用'htmlTable'或'huxtable'。这是因为它们都支持复杂的多级和多嵌套headers。
但是,如果您想使用 '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))
我喜欢将我的 expss
表格通过管道传输到 kable
中以访问一些额外的格式设置选项。这有时需要一些调整,我正在寻找一个调整来摆脱示例中 header 第一列中的 row_labels 文本下面。
简单表示:
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))
生成这个:
谢谢!
输出expss表最好使用'htmlTable'或'huxtable'。这是因为它们都支持复杂的多级和多嵌套headers。 但是,如果您想使用 '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))