在 Rmarkdown 中自动将表格放入选项卡中

发布于 2025-01-18 05:56:52 字数 688 浏览 3 评论 0 原文

我想在自动的不同选项卡中放置从中生成的表。我从

但对于表来说不正常。它创建了标签,但没有显示它们中的表格。有人可以纠正我的代码吗?

---
output: html_document
---

# title 1 {.tabset}
There should be one table in each tab. 

```{r echo=FALSE, warning=FALSE, results='asis'}
for(Species in levels(iris$Species)){
  cat('\n##', Species, '\n')
  p <- iris[iris$Species == Species,]
  knitr::kable(p)
  cat('\n')
}
```

“图像显示我的输出;没有表!”

I want to put tables produced from a for() loop in different tabs automatically. I used the code below from similar code for plots

but it doesn't work properly for tables. It creates the tabs but doesn't show the tables in them. Could anyone please correct my code?

---
output: html_document
---

# title 1 {.tabset}
There should be one table in each tab. 

```{r echo=FALSE, warning=FALSE, results='asis'}
for(Species in levels(iris$Species)){
  cat('\n##', Species, '\n')
  p <- iris[iris$Species == Species,]
  knitr::kable(p)
  cat('\n')
}
```

The image shows my output; No table!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

隐诗 2025-01-25 05:56:52

您必须在循环的打印您的表格:

---
output: html_document
---

# title 1 {.tabset}
There should be one table in each tab. 

```{r echo=FALSE, warning=FALSE, results='asis'}
for(Species in levels(iris$Species)){
  cat('\n##', Species, '\n')
  p <- iris[iris$Species == Species,]
  print(knitr::kable(p))
  cat('\n')
}
```

“在此处输入图像说明”

You have to print your tables within the for loop:

---
output: html_document
---

# title 1 {.tabset}
There should be one table in each tab. 

```{r echo=FALSE, warning=FALSE, results='asis'}
for(Species in levels(iris$Species)){
  cat('\n##', Species, '\n')
  p <- iris[iris$Species == Species,]
  print(knitr::kable(p))
  cat('\n')
}
```

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文