library(htmltab)
LINK6="https://es.wikipedia.org/wiki/Elecciones_parlamentarias_de_Per%C3%BA_de_2016"
GMT='//*[@id="mw-content-text"]/div/table[6]/tbody/tr/td/table'
elec=htmltab(doc= LINK6,
              which = GMT)
names(elec)
## [1] "Distrito Electoral"   "Escaños"              "Congresistas electos"
## [4] "Congresistas electos" "Partido"              "Votos"
str(elec)
## '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" ...
library(readr)
elec[,c(2,3,6)]=lapply(elec[,c(2,3,6)], parse_number)
elec=elec[,c(5,6)]
elec$Votos=as.numeric(elec$Votos)
elec$Partido=as.factor(elec$Partido)
elec$Votos
##   [1]  15  12  20   9  24  21  13  10  15  26  24  19  20  27  24  16  11
##  [18]  20  11   8  30  14   7   6  30  25  18  17  22  31  23  19  14   8
##  [35]  16   9  19  16  27  20  18  15  14  19  18  16  20 103  25  52  57
##  [52]  43  19  15  28  48  44  19  15  58  52  48  48  27 122  57  40  97
##  [69]  53  27 326 186 139  82  58  56  50  49  29  27  23  23  23  13  12
##  [86] 215 112  80  78  73  41  36  30  29  26  34  29  28  13  26  15  10
## [103]  18   2  11   3   7   5  18  15  39  35  26  20  19  55  22  12  28
## [120]  16  25  18  10   7  23  11  17  13  12  10

sis es parametrica

str(elec)
## 'data.frame':    130 obs. of  2 variables:
##  $ Partido: Factor w/ 6 levels "Acción Popular",..: 5 5 2 4 5 5 5 4 5 1 ...
##  $ Votos  : num  15 12 20 9 24 21 13 10 15 26 ...
library(ggpubr)
## Loading required package: ggplot2
## Loading required package: magrittr
ggqqplot(data=elec,x="Partido") + facet_grid(. ~ Votos)
## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

## Warning: Computation failed in `stat_qq_line()`:
## factors are not allowed

f1=formula(Votos ~ Partido)
aggregate(f1, elec, mean)
##                    Partido    Votos
## 1           Acción Popular 41.20000
## 2 Alianza para el Progreso 34.22222
## 3          Alianza Popular 59.80000
## 4            Frente Amplio 23.70000
## 5           Fuerza Popular 30.78082
## 6   Peruanos por el Kambio 48.16667
# funcion ad-hoc
normalidadTest=function(x) {y =shapiro.test(x); 
                            c(y$statistic, y$p.value)}
# calculando
resultado= aggregate(f1, elec,
                     FUN = normalidadTest) 


# mostrando resultado
library(knitr)

shapiroTest=as.data.frame(resultado[,2])
names(shapiroTest)=c("SW_Statistic","Probabilidad")
kable(cbind(resultado[1],shapiroTest))
Partido SW_Statistic Probabilidad
Acción Popular 0.8730698 0.2790776
Alianza para el Progreso 0.7129150 0.0020080
Alianza Popular 0.8299864 0.1390880
Frente Amplio 0.6847797 0.0000256
Fuerza Popular 0.4544075 0.0000000
Peruanos por el Kambio 0.6915787 0.0000638