表中的格式和输出

Sop*_*a J 3 r r-markdown

任何人都可以给我任何关于如何在R(链接)中输出此表的提示?例如,如何加粗第一行,添加虚线,并为表格制作双重标题.我更喜欢R降价,rft也行,我试图避免使用Latex.非常感谢!!

在此输入图像描述

raw*_*awr 6

这是使用htmlTable包的一种方式

install.packages('devtools')
devtools::install_github('gforge/htmlTable')
Run Code Online (Sandbox Code Playgroud)

(你也可以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)',
                   '&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>')
Run Code Online (Sandbox Code Playgroud)

给我这个

在此输入图像描述

用虚线进入问题(头痛).建议只使用固体

  • 虚线可以通过参数`css.tspanner.sep ="border-top:1px点缀黑色"添加,但观众无法正确显示它(我已经为此提交了Chrome错误报告).你也应该代替`rbind(out [1:4] ...)`我建议你把tspanner设置为`c('','Subsets:')`和n.tspanner到`c(4, 2)`. (2认同)