1. Librería

library(dplyr)
library(knitr)
library(kableExtra)

2.Leer Datos

variables <- read.csv("C:/Users/WAN/Downloads/GlobalWeatherRepository.csv")

3.Variable Depurada

Latitud <- na.omit(variables$latitude)

# Total de datos

n_total <- length(Latitud)

4.Medidas de Frecuencia

valor_min <- min(Latitud)
valor_max <- max(Latitud)

rango <- valor_max - valor_min

5.Regla de Sturges

K_sturges <- floor(1 + 3.322 * log10(n_total))

cat("Número de clases:", K_sturges, "\n")
## Número de clases: 18

6.Tabla 4 -> Sturges Real

# Amplitud real
A_sturges <- rango / K_sturges

cat("Amplitud Sturges:", A_sturges, "\n")
## Amplitud Sturges: 5.858333
# Intervalos
Li1 <- seq( valor_min,
  valor_max - A_sturges,
  by = A_sturges
)

Ls1 <- Li1 + A_sturges

7. Frecuencias

ni1 <- numeric(length(Li1))

for(i in 1:length(Li1)){
  
  if(i == length(Li1)){
    
    ni1[i] <- sum(
      Latitud >= Li1[i] &
        Latitud <= Ls1[i]
    )
    
  } else {
    
    ni1[i] <- sum(
      Latitud >= Li1[i] &
        Latitud < Ls1[i]
    )
  }
}

# Frecuencia relativa
hi1 <- (ni1 / sum(ni1)) * 100

# Acumuladas
Ni_asc1 <- cumsum(ni1)
Hi_asc1 <- cumsum(hi1)

Ni_dsc1 <- rev(cumsum(rev(ni1)))
Hi_dsc1 <- rev(cumsum(rev(hi1)))

# Marca de clase
MC1 <- (Li1 + Ls1)/2

8.Tabla según Sturges

Tabla_Sturges <- data.frame(
  
  Lim_inf = round(Li1,2),
  
  Lim_sup = round(Ls1,2),
  
  MC = round(MC1,2),
  
  ni = ni1,
  
  hi = round(hi1,2),
  
  Ni_asc = Ni_asc1,
  
  Hi_asc = round(Hi_asc1,2),
  
  Ni_dsc = Ni_dsc1,
  
  Hi_dsc = round(Hi_dsc1,2)
)


Tabla_Sturges <- rbind(Tabla_Sturges)
colnames(Tabla_Sturges) <- c("Lim. Inf.","Lim. Sup.","MC", "ni", "hi (%)","Ni Asc","Hi Asc","Ni Dsc","Hi Dsc")

kable(Tabla_Sturges, align = "c",
      caption = "Tabla N4: Distribución de frecuencia de latitud del mundo, mediante de los datos obtenidos en Datased de los años 2024 hasta 2026") |> 
  kable_styling(full_width = TRUE, position = "center",
                bootstrap_options = c("striped", "hover", "condensed", "responsive")) |> 
  row_spec(0, bold = TRUE, color = "white", background = "#2C3E50") |> 
  row_spec(nrow(Tabla_Sturges), bold = TRUE, background = "#EAEDED") |> 
  footnote(general = "Fuente: Elaborado por: Grupo 2  
           A partir del repositorio global de datos meteorologicos
           https://www.kaggle.com/datasets/nelgiriyewithana/global-weather-repository\n.",
           general_title = "Nota: ",
           footnote_as_chunk = TRUE,
           title_format = c("italic", "bold"))
Tabla N4: Distribución de frecuencia de latitud del mundo, mediante de los datos obtenidos en Datased de los años 2024 hasta 2026
Lim. Inf. Lim. Sup. MC ni hi (%) Ni Asc Hi Asc Ni Dsc Hi Dsc
-41.30 -35.44 -38.37 728 0.51 728 0.51 141703 100.00
-35.44 -29.58 -32.51 2905 2.05 3633 2.56 140975 99.49
-29.58 -23.72 -26.65 4095 2.89 7728 5.45 138070 97.44
-23.72 -17.87 -20.80 5087 3.59 12815 9.04 133975 94.55
-17.87 -12.01 -14.94 4356 3.07 17171 12.12 128888 90.96
-12.01 -6.15 -9.08 7269 5.13 24440 17.25 124532 87.88
-6.15 -0.29 -3.22 5814 4.10 30254 21.35 117263 82.75
-0.29 5.57 2.64 7611 5.37 37865 26.72 111449 78.65
5.57 11.43 8.50 13043 9.20 50908 35.93 103838 73.28
11.43 17.28 14.35 20327 14.34 71235 50.27 90795 64.07
17.28 23.14 20.21 6943 4.90 78178 55.17 70468 49.73
23.14 29.00 26.07 7269 5.13 85447 60.30 63525 44.83
29.00 34.86 31.93 7276 5.13 92723 65.43 56256 39.70
34.86 40.72 37.79 13773 9.72 106496 75.15 48980 34.57
40.72 46.58 43.65 14029 9.90 120525 85.05 35207 24.85
46.58 52.43 49.50 12440 8.78 132965 93.83 21178 14.95
52.43 58.29 55.36 5091 3.59 138056 97.43 8738 6.17
58.29 64.15 61.22 3647 2.57 141703 100.00 3647 2.57
Nota: Fuente: Elaborado por: Grupo 2
A partir del repositorio global de datos meteorologicos
https://www.kaggle.com/datasets/nelgiriyewithana/global-weather-repository
.

9.Tabla 2 -> Latitud en 10 filas

amplitud <- 20

# Intervalos
Li2 <- seq(
  floor(valor_min/20)*20,
  ceiling(valor_max/20)*20 - 20,
  by = 20
)

Ls2 <- Li2 + 20

10.Frecuencias 2

ni2 <- numeric(length(Li2))

for(i in 1:length(Li2)){
  
  if(i == length(Li2)){
    
    ni2[i] <- sum(
      Latitud >= Li2[i] &
        Latitud <= Ls2[i]
    )
    
  } else {
    
    ni2[i] <- sum(
      Latitud >= Li2[i] &
        Latitud < Ls2[i]
    )
  }
}

# Frecuencia relativa
hi2 <- (ni2 / sum(ni2)) * 100

# Acumuladas
Ni_asc2 <- cumsum(ni2)
Hi_asc2 <- cumsum(hi2)

Ni_dsc2 <- rev(cumsum(rev(ni2)))
Hi_dsc2 <- rev(cumsum(rev(hi2)))

# Marca de clase
MC2 <- (Li2 + Ls2)/2

11. Tabla final Latitud en 10 filas

TDF_Latitud <- data.frame(
  
  Lim_inf = round(Li2,2),
  
  Lim_sup = round(Ls2,2),
  
  MC = round(MC2,2),
  
  ni = ni2,
  
  hi = round(hi2,2),
  
  Ni_asc = Ni_asc2,
  
  Hi_asc = round(Hi_asc2,2),
  
  Ni_dsc = Ni_dsc2,
  
  Hi_dsc = round(Hi_dsc2,2)
)



TDF_Latitud <- rbind(TDF_Latitud)
colnames(TDF_Latitud) <- c("Lim. Inf.","Lim. Sup.","MC", "ni", "hi (%)","Ni Asc","Hi Asc","Ni Dsc","Hi Dsc")

kable(TDF_Latitud, align = "c",
      caption = "Tabla N4: Distribución de frecuencia de latitud del mundo, mediante de los datos obtenidos en Datased de los años 2024 hasta 2026") |> 
  kable_styling(full_width = TRUE, position = "center",
                bootstrap_options = c("striped", "hover", "condensed", "responsive")) |> 
  row_spec(0, bold = TRUE, color = "white", background = "#2C3E50") |> 
  row_spec(nrow(TDF_Latitud), bold = TRUE, background = "#EAEDED") |> 
  footnote(general = "Elaborado por Grupo 2  
           Fuente: A partir del repositorio global de datos meteorologicos
           https://www.kaggle.com/datasets/nelgiriyewithana/global-weather-repository\n.",
           general_title = "Nota: ",
           footnote_as_chunk = TRUE,
           title_format = c("italic", "bold"))
Tabla N4: Distribución de frecuencia de latitud del mundo, mediante de los datos obtenidos en Datased de los años 2024 hasta 2026
Lim. Inf. Lim. Sup. MC ni hi (%) Ni Asc Hi Asc Ni Dsc Hi Dsc
-60 -40 -50 727 0.51 727 0.51 141703 100.00
-40 -20 -30 9641 6.80 10368 7.32 140976 99.49
-20 0 -10 20610 14.54 30978 21.86 131335 92.68
0 20 10 45338 32.00 76316 53.86 110725 78.14
20 40 30 27996 19.76 104312 73.61 65387 46.14
40 60 50 35937 25.36 140249 98.97 37391 26.39
60 80 70 1454 1.03 141703 100.00 1454 1.03
Nota: Elaborado por Grupo 2
Fuente: A partir del repositorio global de datos meteorologicos
https://www.kaggle.com/datasets/nelgiriyewithana/global-weather-repository
.