r - 如何在 Rstudio 演示文稿中创建表格

标签 r rstudio r-markdown rpres

我正在尝试在 RStudio .Rpres 文件中创建一个表。以下是我目前从网上搜索得到的内容,但对齐方式不正确。这是最好的方法吗?对对齐有什么建议吗?

Test
=========================================================
| Right | Left | Default | Center |
|------:|:-----|---------|:------:|
|   12  |  12  |    12   |    12  |
|  123  |  123 |   123   |   123  |
|    1  |    1 |     1   |     1  |

  : Demonstration of simple table syntax.

结果:

enter image description here

最佳答案

您可以使用 knitr::kable 打印您的 data.frame

Test
========================================================

```{r, echo=FALSE}
my_df <- iris
knitr::kable(head(my_df))
```

@对齐: 我尝试使用 align = c('l', 'r', 'c', 'r', 'l')?kable 中所述 但它没有用。也许这是一个错误。

输出

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  |

关于r - 如何在 Rstudio 演示文稿中创建表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29267258/

相关文章:

r - 如何安装包以便我可以使用调试器单步调试它的 R 代码?

r - 在 R 中创建自定义因子

r - 检查一个字符串的所有字符是否存在于 r 中的另一个字符串中

javascript - 将滚动条添加到 DataTable 的一侧(封装 DT)

linux - r-base-dev 由于依赖关系不会安装

ubuntu - 在 Ubuntu (GNOME) 16.10 上安装 RStudio x64 失败 - 依赖性问题

RStudio : Refresh viewer output at runtime when plotting graphs

rstudio - 在 Rstudio 中更改背景颜色

html - 如何将 R Markdown block 放在不同的 HTML 标签中?

shiny - 在 RMarkdown 中编织 Shiny 时出错。 appshot.shiny.appobj 中的错误