在单独的页面上打印 data.frame 的每一行,在新行上打印每一列
Print each row of data.frame on separate page and each column on new line
我想在单独的页面上打印 data.frame
或 tibble
的每一行,并在下一行打印以 \n
分隔的字符串。任何提示。
library(tidyverse)
tb1 <-
tibble(
A = c("A1", "A2", "A3")
, B = c("B1", "B2", "B3")
, C = c("C1", "C2", "C3")
)
tb2 <-
tb1 %>%
mutate(Total = paste(A, B, C, sep = " \n ")) %>%
select(Total)
tb2
library(kableExtra)
kbl(x = tb2, format = "latex")
这个 Markdown 块对我有用 -
```
---
title: "temp"
output:
pdf_document: default
---
```{r, echo=FALSE, results='asis'}
tb2 <- structure(list(Total = c("A1 \n B1 \n C1", "A2 \n B2 \n C2",
"A3 \n B3 \n C3")), row.names = c(NA, -3L), class = c("tbl_df",
"tbl", "data.frame"))
for(i in seq(nrow(tb2))) {
cat(gsub('\n', ' \n ', tb2$Total[i]))
cat("\n\n\n\pagebreak\n")
}
```
我想在单独的页面上打印 data.frame
或 tibble
的每一行,并在下一行打印以 \n
分隔的字符串。任何提示。
library(tidyverse)
tb1 <-
tibble(
A = c("A1", "A2", "A3")
, B = c("B1", "B2", "B3")
, C = c("C1", "C2", "C3")
)
tb2 <-
tb1 %>%
mutate(Total = paste(A, B, C, sep = " \n ")) %>%
select(Total)
tb2
library(kableExtra)
kbl(x = tb2, format = "latex")
这个 Markdown 块对我有用 -
```
---
title: "temp"
output:
pdf_document: default
---
```{r, echo=FALSE, results='asis'}
tb2 <- structure(list(Total = c("A1 \n B1 \n C1", "A2 \n B2 \n C2",
"A3 \n B3 \n C3")), row.names = c(NA, -3L), class = c("tbl_df",
"tbl", "data.frame"))
for(i in seq(nrow(tb2))) {
cat(gsub('\n', ' \n ', tb2$Total[i]))
cat("\n\n\n\pagebreak\n")
}
```