library(htmltab)
datademo=list(page="https://en.wikipedia.org/wiki/Democracy_Index",
xpath='//*[@id="mw-content-text"]/div[1]/table[6]/tbody')
demo = htmltab(doc = datademo$page,
which = datademo$xpath,
encoding = "UTF-8")
demo=demo[,c(3:11)]
demo = demo [c(1:4),]
demo=demo[,c(1,5:9)]
names(demo)= c("country","elecproc","funcgov","polpar","polcul","civiliber")
str(demo)
## 'data.frame': 4 obs. of 6 variables:
## $ country : chr " Norway" " New Zealand" " Finland" " Sweden"
## $ elecproc : chr "10.00" "10.00" "10.00" "9.58"
## $ funcgov : chr "9.64" "8.93" "9.29" "9.29"
## $ polpar : chr "10.00" "9.44" "8.89" "8.33"
## $ polcul : chr "10.00" "8.75" "8.75" "10.00"
## $ civiliber: chr "9.12" "9.71" "9.41" "9.12"
demo$elecproc=as.numeric(demo$elecproc)
demo$funcgov=as.numeric(demo$funcgov)
demo$polpar=as.numeric(demo$polpar)
demo$polcul=as.numeric(demo$polcul)
demo$civiliber=as.numeric(demo$civiliber)