library(htmltab)
Elecciones = htmltab(doc = "https://es.wikipedia.org/wiki/Elecciones_parlamentarias_de_Per%C3%BA_de_2016",
which = '//*[@id="mw-content-text"]/div/table[6]/tbody/tr/td/table' )
str (Elecciones)
## 'data.frame': 130 obs. of 6 variables:
## $ Distrito Electoral : chr "Amazonas(al 100,00%)" "Amazonas(al 100,00%)" "Áncash(al 100,00%)" "Áncash(al 100,00%)" ...
## $ Escaños : chr "2" "2" "5" "5" ...
## $ Congresistas electos: chr "2" "1" "2" "1" ...
## $ Congresistas electos: chr "Marita Herrera Arévalo" "Miguel Antonio Castro Grández" "Eloy Ricardo Narváez Soto" "María Elena Foronda Farro" ...
## $ Partido : chr "Fuerza Popular" "Fuerza Popular" "Alianza para el Progreso" "Frente Amplio" ...
## $ Votos : chr "15 312" "12 939" "20 941" "9 094" ...
Pre - procesamiento
Elecciones = Elecciones [,c (5,6)]
Elecciones[,]=lapply(Elecciones[,],trimws,whitespace = "[\\h\\v]")
str (Elecciones)
## 'data.frame': 130 obs. of 2 variables:
## $ Partido: chr "Fuerza Popular" "Fuerza Popular" "Alianza para el Progreso" "Frente Amplio" ...
## $ Votos : chr "15 312" "12 939" "20 941" "9 094" ...