library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
library(readxl)

Importar base de datos

df <- read_excel("/Users/ofna19/Downloads/abarrotes.xlsx")

Entender base de datos

summary(df)
##  vcClaveTienda        DescGiro         Codigo Barras         PLU         
##  Length:200620      Length:200620      Min.   :8.347e+05   Mode:logical  
##  Class :character   Class :character   1st Qu.:7.501e+12   TRUE:1437     
##  Mode  :character   Mode  :character   Median :7.501e+12   NA's:199183   
##                                        Mean   :5.950e+12                 
##                                        3rd Qu.:7.501e+12                 
##                                        Max.   :1.750e+13                 
##      Fecha                             Hora                       
##  Min.   :2020-05-01 00:00:31.08   Min.   :1899-12-31 00:00:00.00  
##  1st Qu.:2020-06-06 13:24:49.08   1st Qu.:1899-12-31 13:12:42.75  
##  Median :2020-07-11 14:10:21.46   Median :1899-12-31 17:35:59.00  
##  Mean   :2020-07-19 15:19:40.65   Mean   :1899-12-31 16:43:52.05  
##  3rd Qu.:2020-08-29 22:07:47.33   3rd Qu.:1899-12-31 20:47:06.00  
##  Max.   :2020-11-11 23:53:47.73   Max.   :1899-12-31 23:59:59.00  
##     Marca            Fabricante          Producto             Precio       
##  Length:200620      Length:200620      Length:200620      Min.   :-147.00  
##  Class :character   Class :character   Class :character   1st Qu.:  11.00  
##  Mode  :character   Mode  :character   Mode  :character   Median :  16.00  
##                                                           Mean   :  19.42  
##                                                           3rd Qu.:  25.00  
##                                                           Max.   :1000.00  
##    Ult.Costo         Unidades         F.Ticket      NombreDepartamento
##  Min.   :  0.38   Min.   : 0.200   Min.   :     1   Length:200620     
##  1st Qu.:  8.46   1st Qu.: 1.000   1st Qu.: 33967   Class :character  
##  Median : 12.31   Median : 1.000   Median :105996   Mode  :character  
##  Mean   : 15.31   Mean   : 1.262   Mean   :193994                     
##  3rd Qu.: 19.23   3rd Qu.: 1.000   3rd Qu.:383008                     
##  Max.   :769.23   Max.   :96.000   Max.   :450040                     
##  NombreFamilia      NombreCategoria       Estado              Mts_2     
##  Length:200620      Length:200620      Length:200620      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_ubicacion         Giro            Hora_inicio                    
##  Length:200620      Length:200620      Min.   :1899-12-31 07:00:00.00  
##  Class :character   Class :character   1st Qu.:1899-12-31 07:00:00.00  
##  Mode  :character   Mode  :character   Median :1899-12-31 08:00:00.00  
##                                        Mean   :1899-12-31 07:35:49.71  
##                                        3rd Qu.:1899-12-31 08:00:00.00  
##                                        Max.   :1899-12-31 09:00:00.00  
##   Hora_cierre                    
##  Min.   :1899-12-31 21:00:00.00  
##  1st Qu.:1899-12-31 22:00:00.00  
##  Median :1899-12-31 22:00:00.00  
##  Mean   :1899-12-31 22:23:11.42  
##  3rd Qu.:1899-12-31 23:00:00.00  
##  Max.   :1899-12-31 23:00:00.00
count(df,vcClaveTienda,sort=TRUE)
count(df,DescGiro,sort=TRUE)
count(df,Marca,sort=TRUE)
count(df,Fabricante,sort=TRUE)
count(df,Producto,sort=TRUE)
count(df,NombreDepartamento,sort=TRUE)
count(df,NombreFamilia,sort=TRUE)
count(df,NombreCategoria,sort=TRUE)
count(df,Estado,sort=TRUE)
count(df,Mts_2,sort=TRUE)
count(df,Tipo_ubicacion,sort=TRUE)
count(df,Giro,sort=TRUE)
count(df,Hora_inicio,sort=TRUE)
count(df,Hora_cierre,sort=TRUE)

Tabla de frecuencia

table(df$NombreDepartamento)
## 
##            Abarrotes   Bebes e Infantiles               Carnes 
##               198274                 1483                    1 
##             Farmacia           Ferretería             Mercería 
##                  255                  377                   44 
##            Papelería Productos a Eliminar      Vinos y Licores 
##                   74                    8                  104
table(df$Estado)
## 
##      Chiapas      Jalisco   Nuevo León Quintana Roo      Sinaloa 
##         4051         6629        96464        10021        83455

Tablas cruzadas

library(janitor)
## 
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
tabla1 <- tabyl(df, vcClaveTienda, NombreDepartamento)

Gráficos de datos cualitativos

Gráfico de barras

df$Subtotal <- df$Precio*df$Unidades
ggplot(df, aes(x = vcClaveTienda, y = Subtotal, fill = vcClaveTienda)) +
  geom_bar(stat = "identity") +
  theme_minimal()

Diagrama de pareto

library(qcc)
## Package 'qcc' version 2.7
## Type 'citation("qcc")' for citing this R package in publications.
tabla1 <- subset(tabla1, select=c(vcClaveTienda, Abarrotes))
pareto.chart(tabla1$Abarrotes)

##    
## Pareto chart analysis for tabla1$Abarrotes
##        Frequency    Cum.Freq.   Percentage Cum.Percent.
##   A 9.541000e+04 9.541000e+04 4.812028e+01 4.812028e+01
##   D 8.223400e+04 1.776440e+05 4.147493e+01 8.959521e+01
##   E 1.001400e+04 1.876580e+05 5.050587e+00 9.464579e+01
##   B 6.590000e+03 1.942480e+05 3.323683e+00 9.796948e+01
##   C 4.026000e+03 1.982740e+05 2.030523e+00 1.000000e+02

Gráficos de puntos

plot(df$Precio, df$Unidades, main="Relación entre Precio y Unidades", xlab="Precio", ylab="Unidades")

Gráfica de caja y bogotes

boxplot(df$Precio, horizontal = TRUE)

boxplot(df$Unidades, horizontal= TRUE)

Propuestas

1. Expansion de la oferta de productos de abarrotes

2.Programa de fidelizacion para los clientes

Gracias por su atención

This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Cmd+Shift+Enter.

plot(cars)

Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Cmd+Option+I.

When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Cmd+Shift+K to preview the HTML file).

The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.