是否可以将大 R table 导出到 PDF 文件中?
Is it possible to export a large R table into a PDF file?
我需要导出 table 我在 r 中通过绑定不同的值
enter image description here
我试过 library(gridExtra)
但它不起作用(可能我用错了)
FA=table(ant$municipionombre)
View(FA)
prop.table(table(ant$municipionombre))
#Percentage Relative Frequency/Frecuencia relativa porcentual
FR=FA/margin.table(FA)
View(FR)
#Cumulative Absolute Frequency/Frecuencia absoluta acumulada
FAA=cumsum(FA)
View(FAA)
#Cumulative Percentage Relative Frequency/Frecuencia relativa porcentual acumulada
FRP=cumsum(FA)/margin.table(FA)
View(FRP)
#Percentage by entry
perc=FR*100
perc
#Build a table with all variables (FA, FAA, FR, FRP, perc)
tab1=cbind(FA,FAA,FR,FRP,perc)
tab1
View(tab1)```
使用gridExtra包,你可以考虑下面的代码
maxrow = 35;
npages = ceiling(nrow(df)/maxrow)
pdf("test.pdf", height = 11, width = 8.5)
idx = seq(1, maxrow)
grid.table(df[idx,], rows = NULL)
for (i in 2:npages){
grid.newpage()
if(i * maxrow <= nrow(df)) {
idx = seq(1 + ((1 - 1) * maxrow), i*maxrow)
} else {
idx = seq(1 + ((i - 1) * naxriw), nrow(df))
}
grid.table(df[idx,], rows = NULL)
}
dev.off()
您可能会更改高度或宽度,因此我强烈建议尝试制作单页 pdf。另外df是table写pdf.
我不太理解你上面的代码,因为你没有提供可用的示例数据。但是如何将数据导出为 PDF 的基本问题可以通过 reporter 包来解决。
分为三个步骤:
- 创建 table 内容。
- 创建报告。
- 写出报告。
这是一个使用 iris 数据框的示例。
library(reporter)
tbl <- create_table(iris) %>%
titles("My PDF Report")
rpt <- create_report("c:\temp\test.pdf", output_type = "PDF") %>%
add_content(tbl)
write_report(rpt)
这是 PDF 的一部分:
我需要导出 table 我在 r 中通过绑定不同的值 enter image description here
我试过 library(gridExtra)
但它不起作用(可能我用错了)
FA=table(ant$municipionombre)
View(FA)
prop.table(table(ant$municipionombre))
#Percentage Relative Frequency/Frecuencia relativa porcentual
FR=FA/margin.table(FA)
View(FR)
#Cumulative Absolute Frequency/Frecuencia absoluta acumulada
FAA=cumsum(FA)
View(FAA)
#Cumulative Percentage Relative Frequency/Frecuencia relativa porcentual acumulada
FRP=cumsum(FA)/margin.table(FA)
View(FRP)
#Percentage by entry
perc=FR*100
perc
#Build a table with all variables (FA, FAA, FR, FRP, perc)
tab1=cbind(FA,FAA,FR,FRP,perc)
tab1
View(tab1)```
使用gridExtra包,你可以考虑下面的代码
maxrow = 35;
npages = ceiling(nrow(df)/maxrow)
pdf("test.pdf", height = 11, width = 8.5)
idx = seq(1, maxrow)
grid.table(df[idx,], rows = NULL)
for (i in 2:npages){
grid.newpage()
if(i * maxrow <= nrow(df)) {
idx = seq(1 + ((1 - 1) * maxrow), i*maxrow)
} else {
idx = seq(1 + ((i - 1) * naxriw), nrow(df))
}
grid.table(df[idx,], rows = NULL)
}
dev.off()
您可能会更改高度或宽度,因此我强烈建议尝试制作单页 pdf。另外df是table写pdf.
我不太理解你上面的代码,因为你没有提供可用的示例数据。但是如何将数据导出为 PDF 的基本问题可以通过 reporter 包来解决。
分为三个步骤:
- 创建 table 内容。
- 创建报告。
- 写出报告。
这是一个使用 iris 数据框的示例。
library(reporter)
tbl <- create_table(iris) %>%
titles("My PDF Report")
rpt <- create_report("c:\temp\test.pdf", output_type = "PDF") %>%
add_content(tbl)
write_report(rpt)
这是 PDF 的一部分: