我正在尝试将以下PDF加载到R中,并将表格转换为CSV文件。
我已经尝试了库(pdftools)和库(tabulizer),&我花了一个下午经历各种论坛,但我似乎找不到适合我的答案。我可以使用以下代码将PDF加载到R
x <- pdf_text("~/Desktop/PlantTraitAsia.pdf")
它上传得很好,但它根本不是我可以使用的表格。
以下是PDF文件的链接:
http://vege1.kan.ynu.ac.jp/traits/PlantTraitAsia.pdf
我只想将表格上传到R,保留标题,并能够将其导出到TXT,CSV或XLS文件。
感谢您的帮助
答案 0 :(得分:2)
这在我的机器上运行良好:
zz <- tabulizer::extract_tables("http://vege1.kan.ynu.ac.jp/traits/PlantTraitAsia.pdf", pages = 2)
head(zz[[1]])
这会产生:
[,1] [,2] [,3]
[1,] "ID" "Category\rof\rpermissio" "Species"
[2,] "83" "A" "Abies mariesii Masters"
[3,] "155" "A" "Abies mariesii Masters"
[4,] "225" "A" "Abies mariesii Masters"
[5,] "297" "A" "Abies mariesii Masters"
[6,] "369" "A" "Abies mariesii Masters"
[,4] [,5] [,6]
[1,] "Traits" "Value" "Notes"
[2,] "Maximum heighyt (m)" "18.17" ""
[3,] "Shade tolerance (min. relative\rlight intensity, %), Anderson\r1964. J. Ecol." "1.15" ""
[4,] "Length of fruit (mm)" "8" ""
[5,] "Pollination mode" "Anemophily" ""
[6,] "Type of fruit" "Wing-hair" ""
仅获取标题(表格的第一行):
zz[[1]][1,]