在Rmd文件中包含apsrtable(或stargazer)输出 [英] Include apsrtable (or stargazer) output in an Rmd file
问题描述
我尝试使用以下代码将lm
对象的摘要包含在Rmd文件中,但它不起作用.你能帮我吗?
I tried to include the summary of an lm
object in an Rmd file, using code like the following but it didn't work. Could you help me do that?
```{r summary_lm, results='asis', echo=FALSE, comment=NA}
library(apsrtable)
my_model <- lm(y ~ x, data = data.frame(y = rnorm(10), x = 1:10))
res <- apsrtable(my_model) # my_model is a linear regression model (lm)
cat("$$latex \n",res,"\n$$ \n")
```
推荐答案
$$
语法仅适用于数学表达式,并且您试图在其中放入表格,该表格将不起作用.据我了解,apsrtable
仅适用于LaTeX,但LaTeX和Markdown却大不相同-几乎没有希望您可以完全使用Markdown重做LaTeX.我认为人们已经为Markdown发明了$$
语法,因为它得到了MathJax的良好支持,并注意到基于原始Markdown的许多变体/风味.
The $$
syntax only applies to math expressions, and you were trying to put a table in it, which will not work. The apsrtable
, as far as I understand, is for LaTeX only, but LaTeX and Markdown are very different -- there is little hope you can redo LaTeX entirely with Markdown. I think people invented the $$
syntax for Markdown due to the fact that it is well supported by MathJax, and also note there are many variants/flavors based on the original Markdown.
目前您可以考虑:
- 使用
xtable
或ascii
或R2HTML
包生成HTML表 - 请求
apsrtable
的程序包作者支持HTML表
- use the
xtable
orascii
orR2HTML
package to generate HTML tables - request the package author of
apsrtable
to support HTML tables
这篇关于在Rmd文件中包含apsrtable(或stargazer)输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!