英文:
save_kable as pdf changes structure
问题
我使用以下代码创建了一个表格:
df %>%
mutate_if(is.numeric, round, digits = 2) %>%
kable(format = "simple", caption = "统计评估") %>%
save_kable(file = "test.pdf")
你知道如何修复这个问题吗?是否有替代方法?
编辑: 这是数据:
structure(list(TPR = c(0.934842767295597, 0.92922841571852),
FPR = c(0.516589250165893, 0.525067529460655), ACC = c(0.867615330138182,
0.866211826128489), FAR = c(0.0881670095698295, 0.0834131044726853
), CSI = c(0.85734568558549, 0.856776377557092), BS = c(1.02523463957426,
1.01379194951716), HSS = c(0.444709565304963, 0.419220178831526
), tr = c(0.22, 0.25)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -2L))
这是生成的PDF图像:
英文:
I created a table using
df %>%
mutate_if(is.numeric,round,digits = 2) %>%
kable(format="simple", caption="Statistical evaluation") %>%
save_kable(file="test.pdf")
Do you know how to fix this? Is there an alternative?
EDIT: This is the data
structure(list(TPR = c(0.934842767295597, 0.92922841571852),
FPR = c(0.516589250165893, 0.525067529460655), ACC = c(0.867615330138182,
0.866211826128489), FAR = c(0.0881670095698295, 0.0834131044726853
), CSI = c(0.85734568558549, 0.856776377557092), BS = c(1.02523463957426,
1.01379194951716), HSS = c(0.444709565304963, 0.419220178831526
), tr = c(0.22, 0.25)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -2L))
答案1
得分: 1
这可以完全在kableExtra
中完成。对于PDF输出,通常需要使用format = "latex"
。如果您想编辑表格的外观,kableExtra
有很多选项。
df1 <- structure(list(TPR = c(0.934842767295597, 0.92922841571852),
FPR = c(0.516589250165893, 0.525067529460655), ACC = c(0.867615330138182,
0.866211826128489), FAR = c(0.0881670095698295, 0.0834131044726853
), CSI = c(0.85734568558549, 0.856776377557092), BS = c(1.02523463957426,
1.01379194951716), HSS = c(0.444709565304963, 0.419220178831526
), tr = c(0.22, 0.25)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -2L))
library(kableExtra)
df1 |>
kable(format = "latex",
digits = 2,
caption="Statistical evaluation") |>
save_kable(file="test.pdf")
创建于2023-06-29,使用reprex v2.0.2
英文:
This can be done entirely in kableExtra
. For pdf output typically you do need format = "latex"
. If you want to edit the appearance of the table kableExtra
has plenty of options.
df1 <- structure(list(TPR = c(0.934842767295597, 0.92922841571852),
FPR = c(0.516589250165893, 0.525067529460655), ACC = c(0.867615330138182,
0.866211826128489), FAR = c(0.0881670095698295, 0.0834131044726853
), CSI = c(0.85734568558549, 0.856776377557092), BS = c(1.02523463957426,
1.01379194951716), HSS = c(0.444709565304963, 0.419220178831526
), tr = c(0.22, 0.25)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -2L))
library(kableExtra)
df1 |>
kable(format = "latex",
digits = 2,
caption="Statistical evaluation") |>
save_kable(file="test.pdf")
<sup>Created on 2023-06-29 with reprex v2.0.2</sup>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论