Lectura de la base de datos.

encgraf <- read.csv2("encuesta_graficas.csv", enc = "latin1")

Estructura y resumen de la base de datos

str(encgraf)
## 'data.frame':    50 obs. of  9 variables:
##  $ id         : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ tipo       : Factor w/ 2 levels "barras","círculos": 1 1 1 1 1 1 1 1 1 1 ...
##  $ mayor      : Factor w/ 2 levels "no","si": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Inst_y_apar: num  17 17 17 17 17 17 17 17 17 17 ...
##  $ Cosm_y_aseo: Factor w/ 27 levels "11","11,5","11,6",..: 18 15 7 7 10 7 14 4 7 7 ...
##  $ Farma      : Factor w/ 27 levels "10","10,4","11",..: 14 10 3 5 5 3 10 1 3 1 ...
##  $ Plastico   : Factor w/ 25 levels "10","11","12",..: 5 1 16 19 19 16 1 16 22 13 ...
##  $ Construc   : Factor w/ 24 levels "10","10,1","13",..: 2 19 11 11 11 11 19 11 11 6 ...
##  $ Metalme    : Factor w/ 10 levels "12","17%-?-?-?-?-?",..: 10 7 7 7 4 3 8 4 7 4 ...
summary(encgraf)
##        id             tipo    mayor    Inst_y_apar    Cosm_y_aseo
##  Min.   : 1.0   barras  :25   no:25   Min.   : 6.8   15     :10  
##  1st Qu.:13.2   círculos:25   si:25   1st Qu.:17.0   14     : 6  
##  Median :25.5                         Median :17.0   13     : 5  
##  Mean   :25.5                         Mean   :20.2   12     : 2  
##  3rd Qu.:37.8                         3rd Qu.:17.0   13,2   : 2  
##  Max.   :50.0                         Max.   :95.0   13,5   : 2  
##                                                      (Other):23  
##      Farma       Plastico     Construc     Metalme  
##  12     : 9   10     : 5   5      :12   3,4    :25  
##  13     : 7   8      : 5   4      : 4   4      : 7  
##  10     : 4   9      : 5   6      : 4   5      : 5  
##  11     : 4   12     : 4   7      : 4   3      : 4  
##  14     : 3   8,5    : 4   5,6    : 3   6      : 3  
##  18     : 2   14     : 3   8      : 3   2      : 2  
##  (Other):21   (Other):24   (Other):20   (Other): 4

Verificar la razón de alguna variables mostradas como “factor” en lugar de numéricas.

 table(encgraf$Cosm_y_aseo)
## 
##    11  11,5  11,6    12  12,3  12,6    13  13,2  13,3  13,5  13,6  13,7 
##     1     1     1     2     1     1     5     2     1     2     1     1 
##  13,8    14    15  15,6    16  16,9 17%-?  20,3    21    25    30   5,4 
##     1     6    10     1     1     1     1     1     1     2     2     1 
##  6,05   6,8    75 
##     1     1     1
 table(encgraf$Farma)
## 
##      10    10,4      11    11,4      12    12,1    12,4    12,7    12,8 
##       4       1       4       1       9       1       1       1       1 
##      13      14    14,2      15    16,1      17 17%-?-?    17,8      18 
##       7       3       1       1       1       1       1       1       2 
##      20      23      50     5,2     5,9       6     7,9       9     9,1 
##       1       1       1       1       1       1       1       1       1
 table(encgraf$Plastico)
## 
##        10        11        12        13        14        15 17%-?-?-? 
##         5         1         4         2         3         1         1 
##        30       4,6       5,1       5,7       6,7         7       7,5 
##         1         1         2         1         1         2         1 
##       7,7         8       8,2       8,4       8,5       8,6       8,9 
##         1         5         1         2         4         1         1 
##         9       9,2       9,3       9,7 
##         5         2         1         1
 table(encgraf$Construc)
## 
##          10        10,1          13 17%-?-?-?-?           3           4 
##           1           1           1           1           1           4 
##         4,2         4,3         4,5         4,8           5         5,1 
##           1           1           1           1          12           1 
##         5,2         5,4         5,5         5,6         5,8           6 
##           1           2           1           3           1           4 
##           7         7,5         7,6           8         8,9           9 
##           4           1           1           3           1           2
 table(encgraf$Metalme)
## 
##            12 17%-?-?-?-?-?             2             3           3,4 
##             1             1             2             4            25 
##           3,5             4             5             6           9,9 
##             1             7             5             3             1

Observar la encuesta o encuestas que tenga el problema en cada variable

 subset(encgraf, Cosm_y_aseo == "17%-?")
##    id     tipo mayor Inst_y_apar Cosm_y_aseo   Farma  Plastico    Construc
## 45 45 círculos    si          17       17%-? 17%-?-? 17%-?-?-? 17%-?-?-?-?
##          Metalme
## 45 17%-?-?-?-?-?

Eliminar la encuesta que tiene datos no recuperables.

 encgraf1 <- droplevels(subset(encgraf, Cosm_y_aseo !=  "17%-?"))
 str(encgraf1)
## 'data.frame':    49 obs. of  9 variables:
##  $ id         : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ tipo       : Factor w/ 2 levels "barras","círculos": 1 1 1 1 1 1 1 1 1 1 ...
##  $ mayor      : Factor w/ 2 levels "no","si": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Inst_y_apar: num  17 17 17 17 17 17 17 17 17 17 ...
##  $ Cosm_y_aseo: Factor w/ 26 levels "11","11,5","11,6",..: 18 15 7 7 10 7 14 4 7 7 ...
##  $ Farma      : Factor w/ 26 levels "10","10,4","11",..: 14 10 3 5 5 3 10 1 3 1 ...
##  $ Plastico   : Factor w/ 24 levels "10","11","12",..: 5 1 15 18 18 15 1 15 21 12 ...
##  $ Construc   : Factor w/ 23 levels "10","10,1","13",..: 2 18 10 10 10 10 18 10 10 5 ...
##  $ Metalme    : Factor w/ 9 levels "12","2","3","3,4",..: 9 6 6 6 3 2 7 3 6 3 ...

Función para convertir a numéricos las variables que deberían serlo, cambiando el símbolo de coma por el de punto para decimales.

 cambia_a_num <- function(var1) {
   var2 <- gsub(",",".",var1)
   return(as.numeric(var2))
 }

 encgraf1$Cosm_y_aseo <- cambia_a_num(encgraf1$Cosm_y_aseo)
 encgraf1$Farma <- cambia_a_num(encgraf1$Farma)
 encgraf1$Plastico <- cambia_a_num(encgraf1$Plastico)
 encgraf1$Construc <- cambia_a_num(encgraf1$Construc)
 encgraf1$Metalme <- cambia_a_num(encgraf1$Metalme)

 str(encgraf1)
## 'data.frame':    49 obs. of  9 variables:
##  $ id         : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ tipo       : Factor w/ 2 levels "barras","círculos": 1 1 1 1 1 1 1 1 1 1 ...
##  $ mayor      : Factor w/ 2 levels "no","si": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Inst_y_apar: num  17 17 17 17 17 17 17 17 17 17 ...
##  $ Cosm_y_aseo: num  16.9 15 13 13 13.5 13 14 12 13 13 ...
##  $ Farma      : num  16.1 13 11 12 12 11 13 10 11 10 ...
##  $ Plastico   : num  14 10 8 8.5 8.5 8 10 8 9 7 ...
##  $ Construc   : num  10.1 7 5 5 5 5 7 5 5 4 ...
##  $ Metalme    : num  9.9 4 4 4 3 2 5 3 4 3 ...

Exprotar la base de datos a una nueva base de datos para ser analizada posteriormente.

 write.csv2(encgraf1, file = "encuesta_graficas2.csv", 
            row.names = FALSE,
            fileEncoding= "utf8")