【发布时间】:2020-11-18 00:46:57
【问题描述】:
我有以下代码:
---
title: "test"
author: "author"
date: "2020/11/17"
output: pdf_document
always_allow_html: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r cars}
library(compareGroups)
export2md(createTable(compareGroups(Species~.,data=iris)))
```
我使用以下命令来运行这段代码:
rmarkdown::render("test.Rmd")
我希望表格看起来像这样:
Summary descriptives table by groups of `Species'
setosa versicolor virginica p.overall
N=50 N=50 N=50
Sepal.Length 5.01 (0.35) 5.94 (0.52) 6.59 (0.64) <0.001
Sepal.Width 3.43 (0.38) 2.77 (0.31) 2.97 (0.32) <0.001
Petal.Length 1.46 (0.17) 4.26 (0.47) 5.55 (0.55) <0.001
Petal.Width 0.25 (0.11) 1.33 (0.20) 2.03 (0.27) <0.001
但在我从 Rmarkdown 代码生成的 PDF 中最终看起来像这样:
library(compareGroups)
export2md(createTable(compareGroups(Species~.,data=iris)))
## Warning in export2md(createTable(compareGroups(Species ~ ., data = iris))): You are calling export2md ## -> html format is assigned
Summary descriptives table by groups of ‘Species’
setosa
versicolor
virginica
p.overall
N=50
N=50
N=50
Sepal.Length
5.01 (0.35)
5.94 (0.52)
6.59 (0.64)
<0.001
Sepal.Width
3.43 (0.38)
2.77 (0.31)
2.97 (0.32)
<0.001
Petal.Length
1.46 (0.17)
4.26 (0.47)
5.55 (0.55)
<0.001
Petal.Width
0.25 (0.11)
为什么会这样?如何才能在导出的 pdf 中正确显示表格?
【问题讨论】:
标签: r pdf r-markdown comparegroups