本文介绍了如何在 Rstudio 演示文稿中创建表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 RStudio .Rpres 文件中创建一个表.以下是我目前通过在线搜索获得的信息,但对齐方式不正确.这是最好的方法吗?对对齐有什么建议吗?
I'm trying to create a table in an RStudio .Rpres file. Below is what I have at this point from online searching but the alignment is not correct. Is this the best method? Any suggestions on the alignment?
Test
=========================================================
| Right | Left | Default | Center |
|------:|:-----|---------|:------:|
| 12 | 12 | 12 | 12 |
| 123 | 123 | 123 | 123 |
| 1 | 1 | 1 | 1 |
: Demonstration of simple table syntax.
结果:
推荐答案
您可以使用 knitr::kable
打印您的 data.frame
You can use knitr::kable
to print your data.frame
Test
========================================================
```{r, echo=FALSE}
my_df <- iris
knitr::kable(head(my_df))
```
@对齐方式:我尝试使用 align = c('l', 'r', 'c', 'r', 'l')
如 ?kable
中所述但它没有用.也许这是一个错误.
@alignments:I tried using align = c('l', 'r', 'c', 'r', 'l')
as described in ?kable
but it did not work. Maybe this is a bug.
输出
knitr::kable(head(iris), align = c('l', 'r', 'c', 'r', 'l'))
|Sepal.Length | Sepal.Width| Petal.Length | Petal.Width|Species |
|:------------|-----------:|:------------:|-----------:|:-------|
|5.1 | 3.5| 1.4 | 0.2|setosa |
|4.9 | 3.0| 1.4 | 0.2|setosa |
|4.7 | 3.2| 1.3 | 0.2|setosa |
|4.6 | 3.1| 1.5 | 0.2|setosa |
|5.0 | 3.6| 1.4 | 0.2|setosa |
|5.4 | 3.9| 1.7 | 0.4|setosa |
这篇关于如何在 Rstudio 演示文稿中创建表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!