gpt4 book ai didi

r - Hmisc 使用 rowname = NULL 分隔列标题

转载 作者:行者123 更新时间:2023-12-03 18:23:13 26 4
gpt4 key购买 nike

我正在尝试在由组分隔的标题下方设置列标题和水平线。当我执行以下操作时,它会起作用,

library(Hmisc)
data(mtcars)
latex(mtcars, file ='', cgroup = c("Group 1", "Group 2"), n.cgroup = c(5, 6))

enter image description here

但是当我尝试删除行名时,第 1 组和第 2 组下的行合并到同一行
library(Hmisc)
data(mtcars)
latex(mtcars, file ='', cgroup = c("Group 1", "Group 2"), n.cgroup = c(5, 6), rowname = NULL)

enter image description here

有谁知道解决这个问题的方法?

最佳答案

使用我自己的 huxtable 包的一种方法:

library(huxtable)
mt_hux <- as_huxtable(mtcars, add_rownames = TRUE, add_colnames = TRUE)
mt_hux <- insert_column(mt_hux, rep("", nrow(mt_hux)), after = 6)
mt_hux <- insert_row(mt_hux, c("", "Group 1", "", "", "", "", "", "Group 2", "", "", "", "", ""))
mt_hux[2, 1] <- "" # get rid of ugly 'row names'

colspan(mt_hux)[1, c(2, 8)] <- c(5, 6)
align(mt_hux)[1, c(2, 8)] <- "center"
top_border(mt_hux)[1,] <- 1
bottom_border(mt_hux)[1, c(2, 8)] <- 1
bottom_border(mt_hux)[2,] <- 1

# this should be what you want:
mt_hux

这有一个限制:你不能得到漂亮的双线。但是你可以改变线宽,如果这是一个足够的替代品。你也可以试试 pixiedust包裹。

关于r - Hmisc 使用 rowname = NULL 分隔列标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19896844/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com