1. Carga de Librerías

library(dplyr)
library(gt)
if (!require(moments)) install.packages("moments", repos = "https://cloud.r-project.org")
## package 'moments' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\HP\AppData\Local\Temp\RtmpCyWGIQ\downloaded_packages
library(moments)

2. Carga de Datos

# NOTA: no se usa setwd(). Al hacer Knit, RStudio ya usa como carpeta
# de trabajo la misma carpeta donde está guardado este archivo .Rmd.
# Simplemente coloca el CSV original (sin renombrar) en esa misma carpeta.

archivo_csv <- "produccin-de-pozos-de-gas-y-petrleo-no-convencional.csv"

if (!file.exists(archivo_csv)) {
  stop("No se encontró '", archivo_csv, "' en esta carpeta.\n",
       "Archivos que SÍ están en esta carpeta: ",
       paste(list.files(), collapse = ", "))
}

Datos <- read.csv(archivo_csv, sep = ";", fileEncoding = "UTF-8-BOM")
str(Datos)
## 'data.frame':    400759 obs. of  40 variables:
##  $ idempresa             : chr  "YSUR" "YSUR" "YSUR" "YSUR" ...
##  $ anio                  : int  2018 2015 2017 2018 2015 2017 2018 2016 2017 2018 ...
##  $ mes                   : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ idpozo                : int  132771 131719 145330 132770 136137 131430 132769 135206 131429 132738 ...
##  $ prod_pet              : chr  "7.212" "5.240" "0.00" "3.322" ...
##  $ prod_gas              : chr  "510.173" "1.879.820" "0.00" "101.733" ...
##  $ prod_agua             : chr  "0.34" "1.590" "0.00" "14.2" ...
##  $ iny_agua              : chr  "0" "0.000" "0.00" "0" ...
##  $ iny_gas               : chr  "0" "0.000" "0.00" "0" ...
##  $ iny_co2               : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ iny_otro              : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ tef                   : chr  "30.15" "31.000" "0.00" "31" ...
##  $ vida_util             : chr  "" "" "" "" ...
##  $ tipoextraccion        : chr  "Surgencia Natural" "Surgencia Natural" "Sin Sistema de Extracción" "Surgencia Natural" ...
##  $ tipoestado            : chr  "Extracción Efectiva" "Extracción Efectiva" "En Estudio" "Extracción Efectiva" ...
##  $ tipopozo              : chr  "Gasífero" "Gasífero" "Otro tipo" "Gasífero" ...
##  $ observaciones         : chr  "" "" "" "" ...
##  $ fechaingreso          : chr  "2018-02-10 08:37:14.717426" "2015-02-26 13:35:35.533458" "2017-02-16 13:45:37.233373" "2018-02-10 08:37:14.717426" ...
##  $ rectificado           : chr  "f" "f" "f" "f" ...
##  $ habilitado            : chr  "t" "t" "t" "t" ...
##  $ idusuario             : int  444 5 444 444 5 444 444 5 444 444 ...
##  $ empresa               : chr  "YSUR ENERGÍA ARGENTINA S.R.L." "YSUR ENERGÍA ARGENTINA S.R.L." "YSUR ENERGÍA ARGENTINA S.R.L." "YSUR ENERGÍA ARGENTINA S.R.L." ...
##  $ sigla                 : chr  "APA.RN.EFO-126(d)" "AEA.NQ.Gu-1176d" "APA.Nq.Hua.x-1" "APA.RN.EFO-122(d)" ...
##  $ formprod              : chr  "LAJA" "PREC" "VMUT" "LAJA" ...
##  $ profundidad           : chr  "3820" "2592" "4100" "3814" ...
##  $ formacion             : chr  "lajas" "precuyo" "vaca muerta" "lajas" ...
##  $ idareapermisoconcesion: chr  "FEO" "NDD" "X009" "FEO" ...
##  $ areapermisoconcesion  : chr  "ESTACION FERNANDEZ ORO" "AL NORTE DE LA DORSAL" "HUACALERA" "ESTACION FERNANDEZ ORO" ...
##  $ idareayacimiento      : chr  "Z155" "GUA" "Y325" "Z155" ...
##  $ areayacimiento        : chr  "ESTACION FERNANDEZ ORO" "GUANACO" "HUACALERA" "ESTACION FERNANDEZ ORO" ...
##  $ cuenca                : chr  "NEUQUINA" "NEUQUINA" "NEUQUINA" "NEUQUINA" ...
##  $ provincia             : chr  "Rio Negro" "Neuquén" "Neuquén" "Rio Negro" ...
##  $ coordenadax           : chr  "-6.783.808.193" "-6.924.999.839" "-6.979.045.203" "-6.786.739.055" ...
##  $ coordenaday           : chr  "-3.901.910.996" "-3.886.503.323" "-3.820.704.866" "-3.900.716.726" ...
##  $ tipo_de_recurso       : chr  "NO CONVENCIONAL" "NO CONVENCIONAL" "NO CONVENCIONAL" "NO CONVENCIONAL" ...
##  $ proyecto              : chr  "GAS PLUS" "GAS PLUS" "Sin Proyecto" "GAS PLUS" ...
##  $ clasificacion         : chr  "EXPLOTACION" "EXPLOTACION" "EXPLORACION" "EXPLOTACION" ...
##  $ subclasificacion      : chr  "DESARROLLO" "DESARROLLO" "EXPLORACION" "DESARROLLO" ...
##  $ sub_tipo_recurso      : chr  "TIGHT" "TIGHT" "SHALE" "TIGHT" ...
##  $ fecha_data            : chr  "31/1/2018" "31/1/2015" "31/1/2017" "31/1/2018" ...

3. Extracción de la Variable

# Variable cuantitativa DISCRETA: año
variable <- Datos$anio
nombre_variable <- "Año"

4. Conteo

n_total <- length(variable)
n_na <- sum(is.na(variable))
n_validos <- n_total - n_na

cat("Total de registros:", n_total, "\n")
## Total de registros: 400759
cat("Valores faltantes:", n_na, "\n")
## Valores faltantes: 0
cat("Valores válidos:", n_validos, "\n")
## Valores válidos: 400759

5. Tabla de Frecuencia

# Al ser discreta con pocos valores distintos, se usa una tabla simple
# (una fila por cada año), sin necesidad de agrupar en clases (Sturges).
tabla_frec <- table(variable)

tabla_df <- as.data.frame(tabla_frec)
colnames(tabla_df) <- c("Valor", "ni")
tabla_df$hi <- tabla_df$ni / sum(tabla_df$ni)
tabla_df$hi_porc <- round(tabla_df$hi * 100, 2)

totales <- data.frame(Valor = "TOTAL",
                       ni = sum(tabla_df$ni),
                       hi = sum(tabla_df$hi),
                       hi_porc = sum(tabla_df$hi_porc))
tabla_final <- rbind(tabla_df, totales)

tabla_final_gt <- tabla_final %>%
  gt() %>%
  tab_header(title = md("**Tabla N°1 de Distribución de Frecuencias de Año**")) %>%
  tab_source_note(source_note = "Autor: Mayerli Nazareno") %>%
  cols_label(
    Valor = "Año",
    ni = "Frecuencia (ni)",
    hi_porc = "Porcentaje (hi%)"
  ) %>%
  cols_hide(columns = hi) %>%
  fmt_number(columns = c(hi_porc), decimals = 2) %>%
  tab_options(heading.title.font.size = px(16))

tabla_final_gt
Tabla N°1 de Distribución de Frecuencias de Año
Año Frecuencia (ni) Porcentaje (hi%)
2006 2368 0.59
2007 2442 0.61
2008 2280 0.57
2009 1698 0.42
2010 2038 0.51
2011 2599 0.65
2012 3640 0.91
2013 5184 1.29
2014 8777 2.19
2015 12841 3.20
2016 17225 4.30
2017 20734 5.17
2018 24895 6.21
2019 28917 7.22
2020 31716 7.91
2021 34506 8.61
2022 38918 9.71
2023 43219 10.78
2024 48439 12.09
2025 54222 13.53
2026 14101 3.52
TOTAL 400759 99.99
Autor: Mayerli Nazareno

6. Gráficas

6.1 Diagramas de Barras de Cantidad

par(mar = c(6, 6, 4, 2))
barplot(tabla_df$ni,
        main = "", xlab = "", ylab = "",
        col = "dodgerblue",
        ylim = c(0, max(tabla_df$ni) * 1.15),
        names.arg = tabla_df$Valor,
        cex.names = 0.8, las = 2)
mtext("Cantidad", side = 2, line = 4.5, cex = 1, font = 1)
mtext("Año", side = 1, line = 4)
mtext("Gráfica N°1: Distribución de Cantidad de Registros por Año",
      side = 3, line = 2, adj = 0.5, cex = 0.9, font = 2)

par(mar = c(6, 6, 4, 2))
bp1 <- barplot(tabla_df$ni,
        main = "", xlab = "", ylab = "",
        col = "dodgerblue",
        ylim = c(0, max(tabla_df$ni) * 1.25),
        names.arg = tabla_df$Valor,
        cex.names = 0.8, las = 2)
mtext("Cantidad", side = 2, line = 4.5, cex = 1, font = 1)
mtext("Año", side = 1, line = 4)
mtext("Gráfica N°2: Distribución de Cantidad de Registros por Año (con etiquetas)",
      side = 3, line = 2, adj = 0.5, cex = 0.9, font = 2)
text(x = bp1, y = tabla_df$ni, labels = tabla_df$ni, pos = 3, cex = 0.65, col = "black")

6.2 Diagramas de Barras Porcentual

par(mar = c(6, 4, 4, 2))
barplot(tabla_df$hi_porc,
        main = "", xlab = "", ylab = "Porcentaje %",
        col = "salmon",
        ylim = c(0, max(tabla_df$hi_porc) * 1.15),
        names.arg = tabla_df$Valor,
        cex.names = 0.8, las = 2)
mtext("Año", side = 1, line = 4)
mtext("Gráfica N°3: Distribución Porcentual de Registros por Año",
      side = 3, line = 2, adj = 0.5, cex = 0.9, font = 2)

par(mar = c(6, 4, 4, 2))
bp2 <- barplot(tabla_df$hi_porc,
              main = "", xlab = "", ylab = "Porcentaje %",
              col = "salmon",
              ylim = c(0, max(tabla_df$hi_porc) * 1.3),
              names.arg = tabla_df$Valor,
              cex.names = 0.8, las = 2)
mtext("Año", side = 1, line = 4)
mtext("Gráfica N°4: Distribución Porcentual de Registros por Año (con etiquetas)",
      side = 3, line = 2, adj = 0.5, cex = 0.9, font = 2)
text(x = bp2, y = tabla_df$hi_porc,
     labels = paste0(round(tabla_df$hi_porc, 1), "%"),
     pos = 3, cex = 0.65, col = "black")

6.3 Diagrama de Cajas (Boxplot)

par(mar = c(4, 6, 4, 2))
boxplot(variable,
        main = "", horizontal = TRUE,
        col = "lightblue", xlab = "Año")
mtext("Gráfica N°5: Diagrama de Cajas del Año",
      side = 3, line = 2, adj = 0.5, cex = 0.9, font = 2)

6.4 Ojivas

tabla_ord <- tabla_df[tabla_df$Valor != "TOTAL", ]
valores_num <- as.numeric(as.character(tabla_ord$Valor))
orden <- order(valores_num)
valores_num <- valores_num[orden]
Ni <- cumsum(tabla_ord$ni[orden])

par(mar = c(4, 6, 4, 2))
plot(valores_num, Ni,
     type = "o", pch = 16, col = "darkred",
     xlab = "Año", ylab = "Frecuencia acumulada (Ni)",
     main = "")
mtext("Gráfica N°6: Ojiva del Año",
      side = 3, line = 2, adj = 0.5, cex = 0.9, font = 2)

7. Indicadores Estadísticos

minimo  <- min(variable, na.rm = TRUE)
maximo  <- max(variable, na.rm = TRUE)
media   <- mean(variable, na.rm = TRUE)
mediana <- median(variable, na.rm = TRUE)
moda    <- as.numeric(as.character(tabla_df$Valor[which.max(tabla_df$ni)]))
varianza <- var(variable, na.rm = TRUE)
de      <- sd(variable, na.rm = TRUE)
cv      <- de / media * 100
asimetria <- skewness(variable, na.rm = TRUE)
curtosis  <- kurtosis(variable, na.rm = TRUE)

atipicos <- boxplot.stats(variable)$out
n_atipicos <- length(atipicos)

tabla_indicadores <- data.frame(
  Variable = "Año",
  Rango = paste(minimo, "-", maximo),
  "Media (X)" = round(media, 2),
  "Mediana (Me)" = mediana,
  "Moda (Mo)" = moda,
  "Varianza (V)" = round(varianza, 2),
  "Desv. Est. (Sd)" = round(de, 2),
  "C.V. (%)" = round(cv, 2),
  "Asimetria (As)" = round(asimetria, 2),
  "Curtosis (K)" = round(curtosis, 2),
  check.names = FALSE
)

tabla_indicadores_gt <- tabla_indicadores %>%
  gt() %>%
  tab_header(title = md("**Tabla N°2 de Indicadores del Año**")) %>%
  tab_source_note(source_note = "Autor: Mayerli Nazareno")

tabla_indicadores_gt
Tabla N°2 de Indicadores del Año
Variable Rango Media (X) Mediana (Me) Moda (Mo) Varianza (V) Desv. Est. (Sd) C.V. (%) Asimetria (As) Curtosis (K)
Año 2006 - 2026 2020.61 2021 2025 16.49 4.06 0.2 -1.07 4.11
Autor: Mayerli Nazareno

8. Conclusiones

grado_agrupamiento <- if (cv <= 15) "fuertemente" else if (cv <= 30) "medianamente" else "débilmente"
homogeneidad <- if (cv <= 30) "homogéneo" else "heterogéneo"
zona <- if (media > mediana) "alta" else if (media < mediana) "baja" else "media"
hay_atipicos_txt <- if (n_atipicos > 0) {
  sprintf("con %d valor(es) atípico(s) (%s)", n_atipicos, paste(unique(atipicos), collapse = ", "))
} else {
  "sin valores atípicos"
}
# NOTA: ajusta "beneficioso"/"perjudicial" según el contexto de tu análisis.
comportamiento <- "esperado, ya que refleja el crecimiento histórico del número de registros de pozos año a año"

conclusion <- sprintf(
  "Los valores de **%s** fluctúan entre **%s** y **%s** y giran en torno a **%s** (media), con una desviación estándar de **%s**, %s, siendo un conjunto de datos **%s**, cuyos valores se agrupan **%s** en la parte **%s** de %s. Por lo anterior, el comportamiento es **%s**.",
  nombre_variable, minimo, maximo, round(media, 2), round(de, 2),
  hay_atipicos_txt, homogeneidad, grado_agrupamiento, zona, nombre_variable, comportamiento
)
cat(conclusion)

Los valores de Año fluctúan entre 2006 y 2026 y giran en torno a 2020.61 (media), con una desviación estándar de 4.06, con 7090 valor(es) atípico(s) (2008, 2006, 2007), siendo un conjunto de datos homogéneo, cuyos valores se agrupan fuertemente en la parte baja de Año. Por lo anterior, el comportamiento es esperado, ya que refleja el crecimiento histórico del número de registros de pozos año a año.