如何删除GT表中的一行列标签?
#Preparing the data and loading packages
library(modelsummary);library(tidyverse);library(gt)
as_tibble(mtcars)
df <- mtcars %>% mutate(cyl_ = factor(cyl)) %>%
dplyr::select(cyl_, mpg, vs, am, hp, wt)
#Gets table of descriptive statistics about different subsets of the data
print(t1 <- datasummary_balance(~cyl_,
data = df,
output = "gt"))
#This hides the "Std. Dev." columns
t1 %>% cols_hide(c(3,5,7))
#Now I want to hide the "Mean" column labels, but I want to keep the "cyl_" value column labels. Any ideas how?
我想要这样的东西:
#Preparing the data and loading packages
library(modelsummary);library(tidyverse);library(gt)
as_tibble(mtcars)
df <- mtcars %>% mutate(cyl_ = factor(cyl)) %>%
dplyr::select(cyl_, mpg, vs, am, hp, wt)
#Gets table of descriptive statistics about different subsets of the data
print(t1 <- datasummary_balance(~cyl_,
data = df,
output = "gt"))
#This hides the "Std. Dev." columns
t1 %>% cols_hide(c(3,5,7))
#Now I want to hide the "Mean" column labels, but I want to keep the "cyl_" value column labels. Any ideas how?
I want something like this:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
GT
软件包,您可以将表送到tab_options(column_labels.hidden = true)
以删除列标记。不幸的是,这将删除两个级别:列标题和包含您要保留的cyl
信息的跨度标签。请注意,
dataSummary_balance()
产生一个高度自定义的表,该表旨在用作现成的输出。在这种情况下,只需使用dataSummary()
而不是尝试自定义dataSummary_balance()
(Square peg,round peg,round hole,,, ETC)。例如:Using the
gt
package, you can pipe your table totab_options(column_labels.hidden = TRUE)
to remove column labels. Unfortunately, this will remove both levels: the column headers, and the spanning labels that include thecyl
info you want to keep.Note that
datasummary_balance()
produces a highly customized table which is intended to be used as a ready-made output. In cases like these, it might be easier to just build the custom table you want usingdatasummary()
instead of trying to customizedatasummary_balance()
(square peg, round hole, etc). For example:丑陋的解决方案,但人们总是可以添加cols_label(col_name =“”),作为一种使每个列名称无关的方式。
Ugly solution but one could always add cols_label(col_name = "") as a way of making every column name nothing.