简体   繁体   English

R:表1 output

[英]R: table1 output

Some days ago I found table1 library to get nice tables.几天前,我找到了 table1 库来获得漂亮的表格。

The only one problem (for me), its that output is a HTML table.唯一的一个问题(对我来说),它的 output 是一个 HTML 表。 I am using rtf library to export R table to word, but I dont know how export this output table (HTML) to word.我正在使用 rtf 库将 R 表导出到 word,但我不知道如何将这个 output 表(HTML)导出到 word。

I wonder if exist some posibilty of get a different output.我想知道是否存在获得不同 output 的可能性。 Or a different way to convert to R table.或者以不同的方式转换为 R 表。 I am no using R-studio.我没有使用 R-studio。

Thanks in advance.提前致谢。

library(table1)

table1(~mpg| carb*am,data = mtcars)

Thanks to @r2evans for the information, I could get a R table, maybe I lost a little bit the format but is ok when I export to word with rtf library:感谢@r2evans 提供的信息,我可以得到一个 R 表,也许我丢失了一点格式但是当我用 rtf 库导出到 word 时没问题:

library(rvest)
library(table1)

tbl_1=table1(~mpg| carb*am,data = mtcars)
as.data.frame(read_html(tbl_1) %>% html_table(fill=TRUE))

Note that you can get a lot more control over the output with some other packages.请注意,您可以使用其他一些软件包对 output 进行更多控制。 In the example below I'm using Tplyr and reporter.在下面的示例中,我使用的是 Tplyr 和记者。 Tplyr generates the statistics and reporter will create the RTF. Tplyr 生成统计信息,reporter 将创建 RTF。 It takes a lot more work than table1.它比 table1 需要更多的工作。 But you gain a lot more types of statistics and reports.但是您会获得更多类型的统计数据和报告。 You could basically produce any safety report.您基本上可以制作任何安全报告。

library(Tplyr)
library(reporter)

dt <- tplyr_table(mtcars, am) %>% 
  add_layer(group_count(cyl)) %>% 
  add_layer(group_desc(mpg)) %>% 
  build() 


tbl <- create_table(dt, show_cols = c("ord_layer_index", "row_label1", 
                                      "var1_0", "var1_1")) %>% 
  stub(c("ord_layer_index", "row_label1"), label = "Variables") %>% 
  define(ord_layer_index, label = "Variable", label_row = TRUE,
         format = c("1" = "Cylinders",
                    "2" = "Miles Per Gallon"), 
         dedupe = TRUE, blank_after = TRUE) %>% 
  define(row_label1, label = "", indent = .25) %>% 
  define(var1_0, label = "Automatic", align = "center", n = 19) %>% 
  define(var1_1, label = "Manual", align = "center", n = 13) 

pth <- file.path(tempdir(), "test1.rtf")

rpt <- create_report(pth, 
                     output_type = "RTF",
                     orientation = "portrait") %>% 
  titles("Table 1.0", 
         "Characteristics of MTCars by Transmission Type",
         "Population: All Cars") %>% 
  set_margins(top = 1, bottom = 1) %>% 
  add_content(tbl)

write_report(rpt)

file.show(pth)

Here is the RTF output:这是 RTF output: 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM