Contexto

Una empresa con 5 tiendas en el pais solicita un analisis de sus ventas de abarrotes entre mayo y noviembre del 2020.

Importar la base de datos

#file.choose()
df<- read.csv("C:\\Users\\Acer\\Desktop\\R studio\\abarrotes.csv")

Entender la base de datos

resumen<- summary(df)
resumen
##  vcClaveTienda        DescGiro         Codigo.Barras            PLU        
##  Length:200625      Length:200625      Min.   :8.347e+05   Min.   : 1.00   
##  Class :character   Class :character   1st Qu.:7.501e+12   1st Qu.: 1.00   
##  Mode  :character   Mode  :character   Median :7.501e+12   Median : 1.00   
##                                        Mean   :5.950e+12   Mean   : 2.11   
##                                        3rd Qu.:7.501e+12   3rd Qu.: 1.00   
##                                        Max.   :1.750e+13   Max.   :30.00   
##                                                            NA's   :199188  
##     Fecha               Hora              Marca            Fabricante       
##  Length:200625      Length:200625      Length:200625      Length:200625     
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##    Producto             Precio          Ult.Costo         Unidades     
##  Length:200625      Min.   :-147.00   Min.   :  0.38   Min.   : 0.200  
##  Class :character   1st Qu.:  11.00   1st Qu.:  8.46   1st Qu.: 1.000  
##  Mode  :character   Median :  16.00   Median : 12.31   Median : 1.000  
##                     Mean   :  19.42   Mean   : 15.31   Mean   : 1.262  
##                     3rd Qu.:  25.00   3rd Qu.: 19.23   3rd Qu.: 1.000  
##                     Max.   :1000.00   Max.   :769.23   Max.   :96.000  
##                                                                        
##     F.Ticket      NombreDepartamento NombreFamilia      NombreCategoria   
##  Min.   :     1   Length:200625      Length:200625      Length:200625     
##  1st Qu.: 33964   Class :character   Class :character   Class :character  
##  Median :105993   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :193990                                                           
##  3rd Qu.:383005                                                           
##  Max.   :450040                                                           
##                                                                           
##     Estado              Mts.2      Tipo.ubicación         Giro          
##  Length:200625      Min.   :47.0   Length:200625      Length:200625     
##  Class :character   1st Qu.:53.0   Class :character   Class :character  
##  Mode  :character   Median :60.0   Mode  :character   Mode  :character  
##                     Mean   :56.6                                        
##                     3rd Qu.:60.0                                        
##                     Max.   :62.0                                        
##                                                                         
##  Hora.inicio        Hora.cierre       
##  Length:200625      Length:200625     
##  Class :character   Class :character  
##  Mode  :character   Mode  :character  
##                                       
##                                       
##                                       
## 
#install.packages('tidyverse')
library(tidyverse) #libreria para visualizar y manipular los datos.
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
tibble(df) #visulaiza los primeros 10 renglones de la tabla.
## # A tibble: 200,625 × 22
##    vcClaveTienda DescGiro  Codigo.Barras   PLU Fecha      Hora  Marca Fabricante
##    <chr>         <chr>             <dbl> <int> <chr>      <chr> <chr> <chr>     
##  1 MX001         Abarrotes 7501020540666    NA 19/06/2020 08:1… NUTR… MEXILAC   
##  2 MX001         Abarrotes 7501032397906    NA 19/06/2020 08:2… DAN … DANONE DE…
##  3 MX001         Abarrotes 7501000112845    NA 19/06/2020 08:2… BIMBO GRUPO BIM…
##  4 MX001         Abarrotes 7501031302741    NA 19/06/2020 08:2… PEPSI PEPSI-COL…
##  5 MX001         Abarrotes 7501026027543    NA 19/06/2020 08:2… BLAN… FABRICA D…
##  6 MX001         Abarrotes 7501020540666    NA 19/06/2020 08:1… NUTR… MEXILAC   
##  7 MX001         Abarrotes 7501032397906    NA 19/06/2020 08:2… DAN … DANONE DE…
##  8 MX001         Abarrotes 7501000112845    NA 19/06/2020 08:2… BIMBO GRUPO BIM…
##  9 MX001         Abarrotes 7501031302741    NA 19/06/2020 08:2… PEPSI PEPSI-COL…
## 10 MX001         Abarrotes 7501026027543    NA 19/06/2020 08:2… BLAN… FABRICA D…
## # ℹ 200,615 more rows
## # ℹ 14 more variables: Producto <chr>, Precio <dbl>, Ult.Costo <dbl>,
## #   Unidades <dbl>, F.Ticket <int>, NombreDepartamento <chr>,
## #   NombreFamilia <chr>, NombreCategoria <chr>, Estado <chr>, Mts.2 <int>,
## #   Tipo.ubicación <chr>, Giro <chr>, Hora.inicio <chr>, Hora.cierre <chr>
str(df) # Visualiza en texto las varables de la tabla, su tipo y ejemplos.
## 'data.frame':    200625 obs. of  22 variables:
##  $ vcClaveTienda     : chr  "MX001" "MX001" "MX001" "MX001" ...
##  $ DescGiro          : chr  "Abarrotes" "Abarrotes" "Abarrotes" "Abarrotes" ...
##  $ Codigo.Barras     : num  7.5e+12 7.5e+12 7.5e+12 7.5e+12 7.5e+12 ...
##  $ PLU               : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ Fecha             : chr  "19/06/2020" "19/06/2020" "19/06/2020" "19/06/2020" ...
##  $ Hora              : chr  "08:16:21" "08:23:33" "08:24:33" "08:24:33" ...
##  $ Marca             : chr  "NUTRI LECHE" "DAN UP" "BIMBO" "PEPSI" ...
##  $ Fabricante        : chr  "MEXILAC" "DANONE DE MEXICO" "GRUPO BIMBO" "PEPSI-COLA MEXICANA" ...
##  $ Producto          : chr  "Nutri Leche 1 Litro" "DANUP STRAWBERRY P/BEBER 350GR NAL" "Rebanadas Bimbo 2Pz" "Pepsi N.R. 400Ml" ...
##  $ Precio            : num  16 14 5 8 19.5 16 14 5 8 19.5 ...
##  $ Ult.Costo         : num  12.3 14 5 8 15 ...
##  $ Unidades          : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ F.Ticket          : int  1 2 3 3 4 1 2 3 3 4 ...
##  $ NombreDepartamento: chr  "Abarrotes" "Abarrotes" "Abarrotes" "Abarrotes" ...
##  $ NombreFamilia     : chr  "Lacteos y Refrigerados" "Lacteos y Refrigerados" "Pan y Tortilla" "Bebidas" ...
##  $ NombreCategoria   : chr  "Leche" "Yogurt" "Pan Dulce Empaquetado" "Refrescos Plástico (N.R.)" ...
##  $ Estado            : chr  "Nuevo León" "Nuevo León" "Nuevo León" "Nuevo León" ...
##  $ Mts.2             : int  60 60 60 60 60 60 60 60 60 60 ...
##  $ Tipo.ubicación    : chr  "Esquina" "Esquina" "Esquina" "Esquina" ...
##  $ Giro              : chr  "Abarrotes" "Abarrotes" "Abarrotes" "Abarrotes" ...
##  $ Hora.inicio       : chr  "08:00" "08:00" "08:00" "08:00" ...
##  $ Hora.cierre       : chr  "22:00" "22:00" "22:00" "22:00" ...
head(df,10) #Muestra los primeros 10 (POrque yo pedi que me muestre 10) renglones de la tabla.
##    vcClaveTienda  DescGiro Codigo.Barras PLU      Fecha     Hora
## 1          MX001 Abarrotes  7.501021e+12  NA 19/06/2020 08:16:21
## 2          MX001 Abarrotes  7.501032e+12  NA 19/06/2020 08:23:33
## 3          MX001 Abarrotes  7.501000e+12  NA 19/06/2020 08:24:33
## 4          MX001 Abarrotes  7.501031e+12  NA 19/06/2020 08:24:33
## 5          MX001 Abarrotes  7.501026e+12  NA 19/06/2020 08:26:28
## 6          MX001 Abarrotes  7.501021e+12  NA 19/06/2020 08:16:21
## 7          MX001 Abarrotes  7.501032e+12  NA 19/06/2020 08:23:33
## 8          MX001 Abarrotes  7.501000e+12  NA 19/06/2020 08:24:33
## 9          MX001 Abarrotes  7.501031e+12  NA 19/06/2020 08:24:33
## 10         MX001 Abarrotes  7.501026e+12  NA 19/06/2020 08:26:28
##                         Marca                 Fabricante
## 1                 NUTRI LECHE                    MEXILAC
## 2                      DAN UP           DANONE DE MEXICO
## 3                       BIMBO                GRUPO BIMBO
## 4                       PEPSI        PEPSI-COLA MEXICANA
## 5  BLANCA NIEVES (DETERGENTE) FABRICA DE JABON LA CORONA
## 6                 NUTRI LECHE                    MEXILAC
## 7                      DAN UP           DANONE DE MEXICO
## 8                       BIMBO                GRUPO BIMBO
## 9                       PEPSI        PEPSI-COLA MEXICANA
## 10 BLANCA NIEVES (DETERGENTE) FABRICA DE JABON LA CORONA
##                              Producto Precio Ult.Costo Unidades F.Ticket
## 1                 Nutri Leche 1 Litro   16.0     12.31        1        1
## 2  DANUP STRAWBERRY P/BEBER 350GR NAL   14.0     14.00        1        2
## 3                 Rebanadas Bimbo 2Pz    5.0      5.00        1        3
## 4                    Pepsi N.R. 400Ml    8.0      8.00        1        3
## 5       Detergente Blanca Nieves 500G   19.5     15.00        1        4
## 6                 Nutri Leche 1 Litro   16.0     12.31        1        1
## 7  DANUP STRAWBERRY P/BEBER 350GR NAL   14.0     14.00        1        2
## 8                 Rebanadas Bimbo 2Pz    5.0      5.00        1        3
## 9                    Pepsi N.R. 400Ml    8.0      8.00        1        3
## 10      Detergente Blanca Nieves 500G   19.5     15.00        1        4
##    NombreDepartamento          NombreFamilia           NombreCategoria
## 1           Abarrotes Lacteos y Refrigerados                     Leche
## 2           Abarrotes Lacteos y Refrigerados                    Yogurt
## 3           Abarrotes         Pan y Tortilla     Pan Dulce Empaquetado
## 4           Abarrotes                Bebidas Refrescos Plástico (N.R.)
## 5           Abarrotes     Limpieza del Hogar                Lavandería
## 6           Abarrotes Lacteos y Refrigerados                     Leche
## 7           Abarrotes Lacteos y Refrigerados                    Yogurt
## 8           Abarrotes         Pan y Tortilla     Pan Dulce Empaquetado
## 9           Abarrotes                Bebidas Refrescos Plástico (N.R.)
## 10          Abarrotes     Limpieza del Hogar                Lavandería
##        Estado Mts.2 Tipo.ubicación      Giro Hora.inicio Hora.cierre
## 1  Nuevo León    60        Esquina Abarrotes       08:00       22:00
## 2  Nuevo León    60        Esquina Abarrotes       08:00       22:00
## 3  Nuevo León    60        Esquina Abarrotes       08:00       22:00
## 4  Nuevo León    60        Esquina Abarrotes       08:00       22:00
## 5  Nuevo León    60        Esquina Abarrotes       08:00       22:00
## 6  Nuevo León    60        Esquina Abarrotes       08:00       22:00
## 7  Nuevo León    60        Esquina Abarrotes       08:00       22:00
## 8  Nuevo León    60        Esquina Abarrotes       08:00       22:00
## 9  Nuevo León    60        Esquina Abarrotes       08:00       22:00
## 10 Nuevo León    60        Esquina Abarrotes       08:00       22:00
tail(df) #Muestra los ultimos 6 renglones de la tabla
##        vcClaveTienda DescGiro Codigo.Barras PLU      Fecha     Hora
## 200620         MX005 Depósito   7.62221e+12  NA 12/07/2020 01:08:25
## 200621         MX005 Depósito   7.62221e+12  NA 23/10/2020 22:17:37
## 200622         MX005 Depósito   7.62221e+12  NA 10/10/2020 20:30:20
## 200623         MX005 Depósito   7.62221e+12  NA 10/10/2020 22:40:43
## 200624         MX005 Depósito   7.62221e+12  NA 27/06/2020 22:30:19
## 200625         MX005 Depósito   7.62221e+12  NA 26/06/2020 23:43:34
##                    Marca    Fabricante                          Producto Precio
## 200620 TRIDENT XTRA CARE CADBURY ADAMS Trident Xtracare Freshmint 16.32G      9
## 200621 TRIDENT XTRA CARE CADBURY ADAMS Trident Xtracare Freshmint 16.32G      9
## 200622 TRIDENT XTRA CARE CADBURY ADAMS Trident Xtracare Freshmint 16.32G      9
## 200623 TRIDENT XTRA CARE CADBURY ADAMS Trident Xtracare Freshmint 16.32G      9
## 200624 TRIDENT XTRA CARE CADBURY ADAMS Trident Xtracare Freshmint 16.32G      9
## 200625 TRIDENT XTRA CARE CADBURY ADAMS Trident Xtracare Freshmint 16.32G      9
##        Ult.Costo Unidades F.Ticket NombreDepartamento NombreFamilia
## 200620      6.92        1   103100          Abarrotes      Dulcería
## 200621      6.92        1   116598          Abarrotes      Dulcería
## 200622      6.92        1   114886          Abarrotes      Dulcería
## 200623      6.92        1   114955          Abarrotes      Dulcería
## 200624      6.92        1   101121          Abarrotes      Dulcería
## 200625      6.92        1   100879          Abarrotes      Dulcería
##        NombreCategoria       Estado Mts.2 Tipo.ubicación       Giro Hora.inicio
## 200620 Gomas de Mazcar Quintana Roo    58        Esquina Mini súper       08:00
## 200621 Gomas de Mazcar Quintana Roo    58        Esquina Mini súper       08:00
## 200622 Gomas de Mazcar Quintana Roo    58        Esquina Mini súper       08:00
## 200623 Gomas de Mazcar Quintana Roo    58        Esquina Mini súper       08:00
## 200624 Gomas de Mazcar Quintana Roo    58        Esquina Mini súper       08:00
## 200625 Gomas de Mazcar Quintana Roo    58        Esquina Mini súper       08:00
##        Hora.cierre
## 200620       21:00
## 200621       21:00
## 200622       21:00
## 200623       21:00
## 200624       21:00
## 200625       21:00
#install.packages('janitor')
library(janitor) # Libreria para explorar y limpiar datos.
## 
## Attaching package: 'janitor'
## 
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
library(dplyr) # Libreria para manipular base de datos.

count(df,vcClaveTienda,sort=TRUE)
##   vcClaveTienda     n
## 1         MX001 96469
## 2         MX004 83455
## 3         MX005 10021
## 4         MX002  6629
## 5         MX003  4051
count(df,DescGiro,sort=TRUE)
##     DescGiro      n
## 1  Abarrotes 100520
## 2 Carnicería  83455
## 3   Depósito  16650
#count(df,Fecha,sort=TRUE)
#count(df,Hora,sort=TRUE)
#count(df,Marca,sort=TRUE)
#count(df,Fabricante,sort=TRUE)
#count(df,Producto,sort=TRUE)
count(df,NombreDepartamento,sort=TRUE)
##     NombreDepartamento      n
## 1            Abarrotes 198279
## 2   Bebes e Infantiles   1483
## 3           Ferretería    377
## 4             Farmacia    255
## 5      Vinos y Licores    104
## 6            Papelería     74
## 7             Mercería     44
## 8 Productos a Eliminar      8
## 9               Carnes      1
#count(df,NombreFamilia,sort=TRUE)
#count(df,NombreCategoria,sort=TRUE)
count(df,Estado,sort=TRUE)
##         Estado     n
## 1   Nuevo León 96469
## 2      Sinaloa 83455
## 3 Quintana Roo 10021
## 4      Jalisco  6629
## 5      Chiapas  4051
count(df,Tipo.ubicación,sort=TRUE)
##   Tipo.ubicación      n
## 1        Esquina 189945
## 2        Rotonda   6629
## 3   Entre calles   4051
count(df,Giro,sort=TRUE)
##         Giro      n
## 1  Abarrotes 183975
## 2 Mini súper  16650
count(df,Hora.inicio,sort=TRUE)
##   Hora.inicio      n
## 1       08:00 106490
## 2       07:00  87506
## 3       09:00   6629
count(df,Hora.cierre,sort=TRUE)
##   Hora.cierre      n
## 1       22:00 103098
## 2       23:00  87506
## 3       21:00  10021
tabyl(df,vcClaveTienda,NombreDepartamento)
##  vcClaveTienda Abarrotes Bebes e Infantiles Carnes Farmacia Ferretería Mercería
##          MX001     95415                515      1      147        245       28
##          MX002      6590                 21      0        4         10        0
##          MX003      4026                 15      0        2          8        0
##          MX004     82234                932      0      102        114       16
##          MX005     10014                  0      0        0          0        0
##  Papelería Productos a Eliminar Vinos y Licores
##         35                    3              80
##          0                    0               4
##          0                    0               0
##         32                    5              20
##          7                    0               0

Con lo anterior se encontraron las siguientes observaciones:
1. La variable PLU tiene mas de 199,000 NA’s.
2. Las variables Fecha, Hora, Hora.inicio y Hora.cierre no tienen formato correcto.
3. Existen precios negativos.
4. No se observo variabe “Ventas” o “Subtotal”.

Tecnicas para limpieza de datos

Tecnica 1. Remover valores irrelevantes

#Eliminar columnas
df<-subset(df,select = -c(PLU,Codigo.Barras))

#Eliminar renglones 
df<-df[df$Precio > 0, ]

Tecnica 2. Eliminar Valores Duplicados

df<-distinct(df)

Tecnica 3. Corregir errores

df$Unidades<-ceiling(df$Unidades)
summary(df)
##  vcClaveTienda        DescGiro            Fecha               Hora          
##  Length:200473      Length:200473      Length:200473      Length:200473     
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##     Marca            Fabricante          Producto             Precio       
##  Length:200473      Length:200473      Length:200473      Min.   :   0.50  
##  Class :character   Class :character   Class :character   1st Qu.:  11.00  
##  Mode  :character   Mode  :character   Mode  :character   Median :  16.00  
##                                                           Mean   :  19.45  
##                                                           3rd Qu.:  25.00  
##                                                           Max.   :1000.00  
##    Ult.Costo         Unidades         F.Ticket      NombreDepartamento
##  Min.   :  0.38   Min.   : 1.000   Min.   :     1   Length:200473     
##  1st Qu.:  8.46   1st Qu.: 1.000   1st Qu.: 33978   Class :character  
##  Median : 12.31   Median : 1.000   Median :106035   Mode  :character  
##  Mean   : 15.31   Mean   : 1.261   Mean   :194101                     
##  3rd Qu.: 19.23   3rd Qu.: 1.000   3rd Qu.:383065                     
##  Max.   :769.23   Max.   :96.000   Max.   :450040                     
##  NombreFamilia      NombreCategoria       Estado              Mts.2     
##  Length:200473      Length:200473      Length:200473      Min.   :47.0  
##  Class :character   Class :character   Class :character   1st Qu.:53.0  
##  Mode  :character   Mode  :character   Mode  :character   Median :60.0  
##                                                           Mean   :56.6  
##                                                           3rd Qu.:60.0  
##                                                           Max.   :62.0  
##  Tipo.ubicación         Giro           Hora.inicio        Hora.cierre       
##  Length:200473      Length:200473      Length:200473      Length:200473     
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
## 

Tecnica 4. Cambiar tipo de variable

df$Fecha <- as.Date(df$Fecha, format = "%d/%m/%Y")
#si el años tiene 4 digitos usar y minuscula si tiene 4 digitos usar Y mayuscula
str(df)
## 'data.frame':    200473 obs. of  20 variables:
##  $ vcClaveTienda     : chr  "MX001" "MX001" "MX001" "MX001" ...
##  $ DescGiro          : chr  "Abarrotes" "Abarrotes" "Abarrotes" "Abarrotes" ...
##  $ Fecha             : Date, format: "2020-06-19" "2020-06-19" ...
##  $ Hora              : chr  "08:16:21" "08:23:33" "08:24:33" "08:24:33" ...
##  $ Marca             : chr  "NUTRI LECHE" "DAN UP" "BIMBO" "PEPSI" ...
##  $ Fabricante        : chr  "MEXILAC" "DANONE DE MEXICO" "GRUPO BIMBO" "PEPSI-COLA MEXICANA" ...
##  $ Producto          : chr  "Nutri Leche 1 Litro" "DANUP STRAWBERRY P/BEBER 350GR NAL" "Rebanadas Bimbo 2Pz" "Pepsi N.R. 400Ml" ...
##  $ Precio            : num  16 14 5 8 19.5 9.5 11 9.5 23.5 12 ...
##  $ Ult.Costo         : num  12.3 14 5 8 15 ...
##  $ Unidades          : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ F.Ticket          : int  1 2 3 3 4 4 4 4 4 5 ...
##  $ NombreDepartamento: chr  "Abarrotes" "Abarrotes" "Abarrotes" "Abarrotes" ...
##  $ NombreFamilia     : chr  "Lacteos y Refrigerados" "Lacteos y Refrigerados" "Pan y Tortilla" "Bebidas" ...
##  $ NombreCategoria   : chr  "Leche" "Yogurt" "Pan Dulce Empaquetado" "Refrescos Plástico (N.R.)" ...
##  $ Estado            : chr  "Nuevo León" "Nuevo León" "Nuevo León" "Nuevo León" ...
##  $ Mts.2             : int  60 60 60 60 60 60 60 60 60 60 ...
##  $ Tipo.ubicación    : chr  "Esquina" "Esquina" "Esquina" "Esquina" ...
##  $ Giro              : chr  "Abarrotes" "Abarrotes" "Abarrotes" "Abarrotes" ...
##  $ Hora.inicio       : chr  "08:00" "08:00" "08:00" "08:00" ...
##  $ Hora.cierre       : chr  "22:00" "22:00" "22:00" "22:00" ...

Tecnica 5. Tratamiento de valores faltantes (NA)

#Cuantos NA tengo en la base de datos?
sum(is.na(df))
## [1] 0
#Cuantos NA tengo por variable?
sapply(df,function(x) sum(is.na(x)))
##      vcClaveTienda           DescGiro              Fecha               Hora 
##                  0                  0                  0                  0 
##              Marca         Fabricante           Producto             Precio 
##                  0                  0                  0                  0 
##          Ult.Costo           Unidades           F.Ticket NombreDepartamento 
##                  0                  0                  0                  0 
##      NombreFamilia    NombreCategoria             Estado              Mts.2 
##                  0                  0                  0                  0 
##     Tipo.ubicación               Giro        Hora.inicio        Hora.cierre 
##                  0                  0                  0                  0
# Borrar todos los registros con NA de la tabla
# df <- na.omit(df)

# Remplazar NA con CEROS (0)
# df[is.na(df)] <- 0

# Remplazar NA con PROMEDIO
# df$PLU[is.na(df$PLU)] <- mean(df$PLU, na.rm=TRUE)

Tecnica 6. Metodos estadisticos

boxplot(df$Precio, horizontal = TRUE)

boxplot(df$Unidades, horizontal = TRUE)

### Agregar columna a la base de datos

df$Subtotal <- df$Ult.Costo * df$Unidades

Exportar base de datos limpia

write.csv(df, file = "abarrotes_df_limpia.csv", row.names = FALSE)
LS0tDQp0aXRsZTogIkxpbXBpZXphIGRlIGRhdG9zIg0KYXV0aG9yOiAiRGllZ28gR3V0aWVycmV6IEZsb3JlcyBBMDE3MjI0NTIiDQpkYXRlOiAiYHIgU3lzLkRhdGUoKWAiDQpvdXRwdXQ6DQogIGh0bWxfZG9jdW1lbnQ6DQogICAgdG9jOiBUUlVFDQogICAgdG9jX2Zsb2F0OiBUcnVlDQogICAgY29kZV9kb3dubG9hZDogVFJVRQ0KICAgIHRoZW1lOiAiY29zbW8iDQogICAgaGlnaGxpZ3RoOiAiemVuYnVybiINCi0tLQ0KDQohW10oQzpcXFVzZXJzXFxBY2VyXFxEZXNrdG9wXFxSIHN0dWRpb1xcYWJhcnJvdGVzIGdpZi5naWYuY3Jkb3dubG9hZCkNCg0KIyMjIENvbnRleHRvIA0KVW5hIGVtcHJlc2EgY29uIDUgdGllbmRhcyBlbiBlbCBwYWlzIHNvbGljaXRhIHVuIGFuYWxpc2lzIGRlIHN1cyB2ZW50YXMgZGUgYWJhcnJvdGVzIGVudHJlIG1heW8geSBub3ZpZW1icmUgZGVsIDIwMjAuDQoNCiMjIyBJbXBvcnRhciBsYSBiYXNlIGRlIGRhdG9zIA0KYGBge3J9DQojZmlsZS5jaG9vc2UoKQ0KZGY8LSByZWFkLmNzdigiQzpcXFVzZXJzXFxBY2VyXFxEZXNrdG9wXFxSIHN0dWRpb1xcYWJhcnJvdGVzLmNzdiIpDQpgYGANCg0KIyMjIEVudGVuZGVyIGxhIGJhc2UgZGUgZGF0b3MNCmBgYHtyfQ0KcmVzdW1lbjwtIHN1bW1hcnkoZGYpDQpyZXN1bWVuDQoNCiNpbnN0YWxsLnBhY2thZ2VzKCd0aWR5dmVyc2UnKQ0KbGlicmFyeSh0aWR5dmVyc2UpICNsaWJyZXJpYSB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