【发布时间】:2019-12-08 10:55:31
【问题描述】:
第一次在这里发帖。
我正在尝试使用Officer 包将一些统计结果输出到Word 文档中。我知道 body_add_* 函数似乎只适用于数据帧。但是,像 gvlma 和 ncvTest 这样的函数和测试输出为具有非常规维度的列表,因此我无法使用 tidyr 包来整理列表,然后再使用 data.frame() 将它们转换为数据框。所以我需要帮助将这些作为列表的文本块添加到 Word 文档中。
到目前为止,我将这个作为 ADF 测试输出的非常好的列表,可以轻松转换为数据框:
# ADF test into dataframe
adf_df = data.frame(adf)
adf_df
ft <- flextable(data = adf_df) %>%
theme_booktabs() %>%
autofit()
# Output table into Word doc
doc <- read_docx() %>%
body_add_flextable(value = ft) %>%
body_add_par(gvlma)
fileout <- "test.docx"
print(doc, target = fileout)
body_add_par(gvlma) 行给出了错误:
Warning messages:
1: In if (grepl("<|>", x)) { :
the condition has length > 1 and only the first element will be used
2: In charToRaw(enc2utf8(x)) :
argument should be a character vector of length 1
all but the first element will be ignored
gvlma 以列表形式输出,这是输出:
Call:
lm(formula = PD ~ ., data = dataset)
Coefficients:
(Intercept) WorldBank_Oil
1.282 -1.449
ASSESSMENT OF THE LINEAR MODEL ASSUMPTIONS
USING THE GLOBAL TEST ON 4 DEGREES-OF-FREEDOM:
Level of Significance = 0.05
Call:
gvlma(x = model)
Value p-value Decision
Global Stat 4.6172 0.3289 Assumptions acceptable.
Skewness 0.1858 0.6664 Assumptions acceptable.
Kurtosis 0.1812 0.6703 Assumptions acceptable.
Link Function 1.7823 0.1819 Assumptions acceptable.
Heteroscedasticity 2.4678 0.1162 Assumptions acceptable.
【问题讨论】:
-
不知道这是否与您感兴趣的内容相去甚远,但是您是否考虑过 R 降价? rmarkdown.rstudio.com
-
嗨!感谢您的回复 :) 我已经尝试过 rmarkdown 但我更愿意先使用 Office 包,因为我不必将单独的一组代码另存为 .rmd
标签: r statistics officer