谁能给我关于如何在R(链接)中输出此表的任何提示?例如,如何加粗第一行,添加虚线并为表格创建双标题。我更喜欢R markdown,rft也可以,我试图避免Latex。非常感谢!!

最佳答案

这是使用htmlTable包的一种方法

install.packages('devtools')
devtools::install_github('gforge/htmlTable')


(您也可以在cran(htmlTable)的Gmisc程序包中找到该函数install.packages('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)',
                   '&emsp;Age > 60','&emsp;Age < 60')

## add padding row called subset
out <- rbind(out[1:4, ], 'Subsets:' = '', out[5:6, ])

## bolding rownames
rownames(out) <- sprintf('<b>%s</b>', rownames(out))

## table column headers (with line breaks (<br />))
cgroup <- c('', 'R + C<br />(n = ***)', 'R + S<br />(n = ***)')

# zzz <- `rownames<-`(out, NULL)

library(htmlTable)
htmlTable(out, rowlabel = 'Adjustment<sup>&dagger;</sup>',
          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 <i>p</i> values of two models and
                     something something.",
          tfoot = '<font size=1><sup>&dagger;</sup>Some note.</font>')


给我这个



用虚线遇到问题(头痛)。建议只使用固体

08-24 15:14