Q 3.2 Scrap data off from the web
- By using R to read from Wikipedia, create a data frame that contains the names of the countries and their healthcare expenditure
- -You can use any Wikipedia pagethat hasa population table in it. You can use any measure of healthcare spending that you find or like.
- -Hint: Severalwiki pages have many countries in one page. Use that!
- -Hint: Consider using readHTMLTable {XML Package}. Any other way is also acceptable. (htmlTreeParse)
Print your entire data frame (2 or more columns) using 'knitr' and submit as HTML file.
library(XML)
library(knitr)
url <- "http://en.wikipedia.org/wiki/List_of_countries_by_total_health_expenditure_%28PPP%29_per_capita"
oecd_table <- readHTMLTable(url)[[2]]
names(oecd_table)[1] <- "Rank"
names(oecd_table)[2] <- "Country.names"
names(oecd_table)[3] <- "Tot.HE.percapitaUSD"
names(oecd_table)[4] <- "Tot.HE.%ofGDP"
oecd_table
## Rank Country.names Tot.HE.percapitaUSD Tot.HE.%ofGDP
## 1 1 United States 8,508 17.7
## 2 2 Norway 5,669 9.3
## 3 3 Switzerland 5,643 11.0
## 4 4 Netherlands 5,099 11.9
## 5 5 Austria 4,546 10.8
## 6 6 Canada 4,522 11.2
## 7 7 Germany 4,495 11.3
## 8 8 Denmark 4,448 10.9
## 9 9 Luxembourg 4,246 6.6
## 10 10 France 4,118 11.6
## 11 11 Belgium 4,061 10.5
## 12 12 Sweden 3,925 9.5
## 13 13 Australia 3,800 (2010) 8.9 (2010)
## 14 14 Ireland 3,700 8.9
## 15 15 United Kingdom 3,405 9.4
## 16 16 Finland 3,374 9.0
## 17 17 Iceland 3,305 9.0
## 18 18 Japan 3,213 (2010) 9.6 (2010)
## 19 19 New Zealand 3,182 10.3
## 20 20 Spain 3,072 9.3
## 21 21 Italy 3,012 9.2
## 22 22 Portugal 2,619 10.2
## 23 23 Taiwan (Republic of China)[3] 2,479 6.6
## 24 24 Slovenia 2,421 8.9
## 25 25 Greece 2,361 9.1
## 26 26 Israel 2,239 7.7
## 27 27 Korea, South 2,198 7.4
## 28 28 Czech Republic 1,966 7.5
## 29 29 Slovakia 1,915 7.9
## 30 30 Hungary 1,689 7.9
## 31 31 Chile 1,568 7.5
## 32 32 Poland 1,452 6.9
## 33 33 Estonia 1,303 5.9
## 34 34 Mexico 977 (2010) 6.2 (2010)
## 35 35 Turkey 906 (2008) 6.1 (2008)