Include apsrtable (or stargazer) output in Rmd file

I tried to include a summary of the lm object in the Rmd file using the following code, but this did not work. could you help me?

 ```{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") ``` 
+6
source share
2 answers

The $$ syntax only applies to mathematical expressions, and you tried to put a table in it that would not work. apsrtable , as I understand it, is only for LaTeX, but LaTeX and Markdown are very different - there is little hope that you can completely remake LaTeX with Markdown. I think people came up with the $$ syntax for Markdown because it is well supported by MathJax, and also note that there are many variations / flavors based on the original Markdown.

At the moment, you might think:

  • use xtable or ascii or R2HTML to generate HTML tables
  • request the author of the apsrtable package to support HTML tables
+6
source

How about including my_model in Markdown format with `panderΛ™ :

 > library(pander) > pander(my_model) -------------------------------------------------------------- &nbsp; Estimate Std. Error t value Pr(>|t|) ----------------- ---------- ------------ --------- ---------- **x** 0.1174 0.1573 0.7465 0.4767 **(Intercept)** -0.2889 0.9759 -0.296 0.7748 -------------------------------------------------------------- Table: Fitting linear model: y ~ x 

Or in PHP format MarkdownExtra / rmarkdown:

 > panderOptions('table.style', 'rmarkdown') > pander(my_model) | &nbsp; | Estimate | Std. Error | t value | Pr(>|t|) | |:-----------------:|:----------:|:------------:|:---------:|:----------:| | **x** | 0.1174 | 0.1573 | 0.7465 | 0.4767 | | **(Intercept)** | -0.2889 | 0.9759 | -0.296 | 0.7748 | Table: Fitting linear model: y ~ x 
+3
source

All Articles