如何在RMarkdown中手动简单地格式化表格,在转换为HTML(使用knitr和markdown包),PDF(使用pandoc和miktex)和docx(使用pandoc)时看起来很好?
我希望能够在RMarkdown中编写小表,这些表不是R函数的结果,这些函数在我最常使用的三种格式中看起来很好.到目前为止,我发现3种格式中有2种格式看起来不错,可能是3/3吗?
一.这在Knit HTML之后看起来不错,但在PDF或docx中并不好
<table>
<tr>
<td>Eggs</td>
<td>Ham</td>
</tr>
<tr>
<td>Basil</td>
<td>Tomato</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
二.这个在Knit HTML之后看起来不错,但在PDF或docx中并不好
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |
Run Code Online (Sandbox Code Playgroud)
三.这个在Knit HTML之后看起来不太好但是在PDF和docx中很好(到目前为止最好的选择)
V1 Tweedledee Tweedledum
-------- -------------- ----------------
Age 14 14
Height 3'2" 3'2"
Politics Conservative Conservative
Religion "New Age" Syrian Orthodox
--------- -------------- ----------------
Run Code Online (Sandbox Code Playgroud)
四.在编织HTML并制作PDF和docx(获胜者!)之后这看起来不错,但不是我之后的手动格式. …
我想根据正在创建的格式包含特定内容.在这个具体的例子中,我的表在MS word输出中看起来很糟糕,但很棒HTML.我想添加一些测试,根据输出省略表.
这是一些伪代码:
output.format <- opts_chunk$get("output")
if(output.format != "MS word"){
print(table1)
}
Run Code Online (Sandbox Code Playgroud)
我确信这不是正确的使用方法opts_chunk,但这是我对如何knitr在幕后工作的理解的限制.测试这个的正确方法是什么?
R Markdown的新版本基于pandoc,因此您可以轻松更改输出格式.
我的问题是从回归模型中获取markdown格式表,因为LATEX和HTML表不能在pandoc转换中存活.
我知道从各种模型(stargazer,texreg,asprtable ......)生成LATEX/HTML输出的包,我知道函数/包,它们从数据框和矩阵生成降价表,但不从其他对象生成.
有什么建议?
我在R中有多个回归模型,我想以一种可以包含在出版物中的漂亮表格格式进行总结.我已经准备好了所有的结果,但是找不到导出它们的方法,而且由于需要大约20个表而手动执行此操作效率不高.
所以,我的一个模型是:
felm1=felm(ROA~BC+size+sizesq+age | stateyeard+industryyeard, data=data)
Run Code Online (Sandbox Code Playgroud)
而且我在R中得到了理想的总结.
但是,我对论文的要求是在表格中只有以下内容,括号中的t统计量和重要性代码(*,等)的估计值.
有没有办法创建任何类型的表将包括上述?Lyx,excel,word,.rft,真的.
更好的是,我拥有的另一个模型(有些变量不同):
felm2=felm(ROA~BC+BCHHI+size+sizesq+age | stateyeard+industryyeard, data=data)
Run Code Online (Sandbox Code Playgroud)
我可以在一个表中汇总两个回归(其中相同的变量将在同一行,其他变量会产生空单元格)?
提前谢谢你,我将不胜感激任何帮助.
这是一个可重复的例子:
x<-rnorm(1:20)
y<-(1:20)/10+x
summary(lm(y~x))
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Itercept) 1.0539 0.1368 7.702 4.19e-07 ***
x 1.0257 0.1156 8.869 5.48e-08 ***
Run Code Online (Sandbox Code Playgroud)
这是R中的结果.我希望表中的结果看起来像
(Itercept) 1.0539*** (7.702)
X 1.0257*** (8.869)
Run Code Online (Sandbox Code Playgroud)
这可能吗?
我想使用 R Markdown 在 HTML 文档中显示回归输出。我尝试了texreg和stargazer包。我现在的问题是,在笔记中我无法将重要的星星带入生活。由于自动生成,我似乎无法摆脱它们。我一直对这个和这个感到困惑,但没有成功。我错过了什么?非常感谢!!
这是一些代码:
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r data}
library(car)
lm1 <- lm(prestige ~ income + education, data=Duncan)
```
## with STARGAZER
```{r table1, results = "asis", message=FALSE}
library(stargazer)
stargazer(lm1, type="html", notes="stargazer html 1") # nothing
stargazer(lm1, type="html", notes="stargazer html 2", star.char = "\\*") # nothing, even gone in table
```
## with TEXREG
```{r table2, results = "asis", message=FALSE}
library(texreg)
htmlreg(lm1, custom.note="%stars. htmlreg") # …Run Code Online (Sandbox Code Playgroud)