[英]How to span header with column in flextable or gtsummary
我们需要tidyr::pivot_wider()
和ftExtra::span_header()
。 如果您希望在列之间留出空白,请使用 flextable 中的“空” flextable
。
library(tidyr)
library(dplyr)
library(flextable)
mtcars %>%
select(mpg, cyl, am) %>%
group_by(cyl, am) %>%
summarise(mean_mpg = mean(mpg),
sd_mpg = sd(mpg)) %>%
pivot_wider(names_from = am, values_from = c(mean_mpg, sd_mpg), names_glue = "am {am}.{.value}", names_vary = "slowest") %>%
flextable(col_keys = c(names(.)[1],"blank1",names(.)[2:3], "blank2", names(.)[4:5] )) |>
ftExtra::span_header(sep = "\\.") |>
empty_blanks()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.