R markdown:如何紧凑地打印数据框
R markdown: how to print dataframe compactly
我正在使用 knitr::kable
来打印我的数据帧,但有时它们太大了。有什么简单的方法可以用滚动条紧凑地打印它们吗?
例如,我这样做:
knitr::kable(mtcars)
如何添加按条件滚动(例如,if nrow > 10
and/or ncol > 10
)?
P.S。 DT::datatable
不适用于大 ncol
:
我需要完全滚动的界面。
您可以添加滚动条。例如,使用 kableExtra
或 DT
:
R 降价
---
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(kableExtra)
```
Some very wide data:
```{r}
df <- cbind(mtcars, mtcars)
```
With `kableExtra`:
```{r}
kable(df) %>%
kable_styling("striped", full_width = F) %>%
scroll_box(width = "100%", height = "200px")
```
Or with `DT`:
```{r}
DT::datatable(
df,
height = 200,
options = list(scrollX = TRUE)
)
```
输出
我正在使用 knitr::kable
来打印我的数据帧,但有时它们太大了。有什么简单的方法可以用滚动条紧凑地打印它们吗?
例如,我这样做:
knitr::kable(mtcars)
如何添加按条件滚动(例如,if nrow > 10
and/or ncol > 10
)?
P.S。 DT::datatable
不适用于大 ncol
:
我需要完全滚动的界面。
您可以添加滚动条。例如,使用 kableExtra
或 DT
:
R 降价
---
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(kableExtra)
```
Some very wide data:
```{r}
df <- cbind(mtcars, mtcars)
```
With `kableExtra`:
```{r}
kable(df) %>%
kable_styling("striped", full_width = F) %>%
scroll_box(width = "100%", height = "200px")
```
Or with `DT`:
```{r}
DT::datatable(
df,
height = 200,
options = list(scrollX = TRUE)
)
```