作者:小菜鸟 | 来源:互联网 | 2023-05-28 21:59
任何人都可以给我任何关于如何在R(链接)中输出此表的提示?例如,如何加粗第一行,添加虚线,并为表格制作双重标题.我更喜欢R降价,rft也行,我试图避免使用Latex.非常感谢!!
1> rawr..:
这是使用htmlTable
包的一种方式
install.packages('devtools')
devtools::install_github('gforge/htmlTable')
(你也可以htmlTable
在cran(install.packages('Gmisc')
)的Gmisc包中找到这个函数,但它很快就会被删除并在一个名为的独立包中提供htmlTable
)
out <-
structure(c("37(34%)", "1 (Ref)", "1 (Ref)", "1 (Ref)", "1 (Ref)",
"1 (Ref)", "45(23%)", "0.68 (0.63, 0.73)", "0.38 (0.32, 0.44)",
"0.21 (0.17, 0.28)", "0.08 (0.05, 0.13)", "0.05 (0.02, 0.11)",
"", "0.03", "0.04", "0.03", "0.02", "0.02", "110(34%)", "0.68 (0.65, 0.71)",
"0.38 (0.34, 0.42)", "0.21 (0.18, 0.25)", "0.08 (0.06, 0.11)",
"0.05 (0.03, 0.08)", "", "0.03", "0.04", "0.03", "0.02", "0.02"
),
.Dim = c(6L, 5L),
.Dimnames = list(NULL, c("r", "hr", "p", "hr", "p")))
## format rows/cols
colnames(out) <- c('(n = ***)','HR (92% CI)','P','HR (92% CI)','P')
rownames(out) <- c('PD No (%)','None','Age','Age (<60 vs > 60)',
' Age > 60',' Age <60')
## add padding row called subset
out <- rbind(out[1:4, ], 'Subsets:' = '', out[5:6, ])
## bolding rownames
rownames(out) <- sprintf('%s', rownames(out))
## table column headers (with line breaks (
))
cgroup <- c('', 'R + C
(n = ***)', 'R + S
(n = ***)')
# zzz <- `rownames<-`(out, NULL)
library(htmlTable)
htmlTable(out, rowlabel = 'Adjustment†',
ctable = TRUE, align = 'ccccc',
## number of columns that each cgroup label spans:
n.cgroup = c(1, 2, 2), cgroup = cgroup,
## insert two table spanning sections:
tspanner = c('',''), # no labels
n.tspanner = c(4, 3), # number of rows to span (must sum to nrow(out))
# css.tspanner.sep = "border-bottom: 1px dotted grey;",
caption = "Table 1: Hazard ratios and p values of two models and
something something.",
tfoot = '†Some note.')
给我这个
用虚线进入问题(头痛).建议只使用固体
虚线可以通过参数`css.tspanner.sep ="border-top:1px点缀黑色"添加,但观众无法正确显示它(我已经为此提交了Chrome错误报告).你也应该代替`rbind(out [1:4] ...)`我建议你把tspanner设置为`c(&#39;&#39;,&#39;Subsets:&#39;)`和n.tspanner到`c(4, 2)`.