您好我想从R -
中的数据框创建以下RTFdf <-
Country N1 Mean1 SD1 N2 Mean2 SD1
----------------------------------------------------
Bangladesh 52 25.03 0.02 43 22.31 0.08
Germany 42 95.01 1.02 53 9.31 0.09
Italy 2 20.22 0.00 11 8.09 1.11
---
我希望报告为:
Treatment A Treatment B
Country N Mean SD N Mean SD
------------------------------------------------------
Bangladesh 52 25.03 0.02 43 22.31 0.08
Germany 42 95.01 1.02 53 9.31 0.09
Italy 2 20.22 0.00 11 8.09 1.11
---
在文本下面有两个下划线&#34;治疗A&#34;和&#34;治疗B&#34;。 象 -
Treatment A
------------------------
N Mean SD
任何人都可以帮助我。
答案 0 :(得分:0)
五年后,终于有一个包可以轻松完成您的要求。它被称为reporter。它是我所知道的唯一可以以 RTF、PDF 和纯文本格式进行报告的 R 包。您可以使用 spanning_header()
函数添加跨越标头。
这是一个例子:
library(reporter)
library(magrittr)
# Sample data
df <- read.table(header = TRUE, text = '
Country N1 Mean1 SD1 N2 Mean2 SD2
Bangladesh 52 25.03 0.02 43 22.31 0.08
Germany 42 95.01 1.02 53 9.31 0.09
Italy 2 20.22 0.00 11 8.09 1.11')
# Create table
tbl <- create_table(df) %>%
column_defaults(width = .5) %>%
spanning_header(N1, SD1, label = "Treatment A") %>%
spanning_header(N2, SD2, label = "Treatment B") %>%
define(Country, width = 1) %>%
titles("Table 1.0", "Treatments by Country") %>%
footnotes("* Country of Site")
# Create report and add table
rpt <- create_report("test.rtf", output_type = "RTF") %>%
options_fixed(uchar = "-") %>%
add_content(tbl)
# Write out report
write_report(rpt)
输出如下:
Table 1.0
Treatments by Country
Treatment A Treatment B
----------------- -----------------
Country N1 Mean1 SD1 N2 Mean2 SD2
-----------------------------------------------
Bangladesh 52 25.03 0.02 43 22.31 0.08
Germany 42 95.01 1.02 53 9.31 0.09
Italy 2 20.22 0 11 8.09 1.11
* Country of Site