The file is divided into continents and its countries , i want continents to be as column headers. I have tried many things but unable to perform the action. here's the link to the pdf file
Asked
Active
Viewed 803 times
-4
-
1Not my downvote, but you're going to need a library to convert PDF to csv. – Tim Biegeleisen May 01 '17 at 08:13
2 Answers
1
If it's just this one file it might be easiest to copy and paste the data by hand.
Else, you'll need a tool to convert the PDF to text (there are some online and offline tools available that do that -- which is best depends on your OS and situation). Then you'll probably need to write some script to rearrange the text and create the csv you want.

Arie B.
- 290
- 1
- 10
1
Here is some ideas that can help you.
I use the package tabulizer
"which bindings to the Tabula java library, which can be used to computationaly extract tables from PDF documents" (link).
library("tabulizer")
continents <- c("Africa","Americas","Asia","Australia/Oceania","Europe")
f <- "Countries_where_English_is_an_official_language.pdf"
(rawTxt1 <- extract_text(f, page=1, encoding="UTF-8"))
# Split according to continents
(rawTxt2 <- strsplit(rawTxt1,"\r\n \r\n")[[1]])
# For trimming leading and trailing whitespace
trim <- function (x) gsub("^\\s+|\\s+$", "", x)
# Organize data in a list
extrTxt <- vector(length(continents),mode="list")
cnt <- 1
for (k in 1:length(rawTxt2)) {
rowk <- rawTxt2[k]
spltxt <- trim(strsplit(rowk,"\r\n")[[1]])
if (spltxt[1] %in% continents) {
extrTxt[[cnt]] <- spltxt
cnt <- cnt +1
}
}
print(extrTxt)
Here is the results:
[[1]]
[1] "Africa" "Botswana" "Cameroon" "Ethiopia" "Eritrea" "The Gambia" "Ghana" "Kenya"
[9] "Lesotho" "Liberia" "Malawi" "Mauritius" "Namibia" "Nigeria" "Rwanda" "Seychelles"
[17] "Sierra Leone" "South Africa" "South Sudan" "Sudan" "Swaziland" "Tanzania" "Uganda" "Zambia"
[25] "Zimbabwe"
[[2]]
[1] "Americas" "Antigua and Barbuda" "The Bahamas"
[4] "Barbados" "Belize" "Canada"
[7] "Dominica" "Grenada" "Guyana"
[10] "Jamaica" "Saint Kitts and Nevis" "Saint Lucia"
[13] "Saint Vincent and the Grenadines" "Trinidad and Tobago" "United States"
[[3]]
[1] "Asia" "India" "Pakistan" "Philippines" "Singapore"
[[4]]
[1] "Australia/Oceania" "Australia" "Fiji"
[4] "Kiribati" "Marshall Islands" "Federated States of Micronesia"
[7] "Nauru" "New Zealand" "Palau"
[10] "Papua New Guinea" "Samoa" "Solomon Islands"
[13] "Tonga" "Tuvalu" "Vanuatu"
[[5]]
[1] "Europe" "Ireland" "Malta" "United Kingdom"

Marco Sandri
- 23,289
- 7
- 54
- 58