⚠️ Advertencia crítica antes de correr cualquier script
No ejecutes scripts de R contra archivos oficiales, bases de datos reales, carpetas institucionales, SQL Server, Access, APIs internas o datasets sensibles sin autorización formal.
R puede transformar, resumir, modelar y visualizar miles o millones de registros rápidamente. Un análisis mal probado puede producir conclusiones incorrectas, sobrescribir archivos, exponer datos sensibles o afectar decisiones de BI, auditoría, presupuesto o producción.
Regla obligatoria del training: primero se trabaja con data sintética, luego con una copia controlada, después se valida el resultado, y solo entonces se considera usar datos reales siguiendo permisos, backup, change control, data governance y protocolos de ciberseguridad.
- Permisos: usa solamente archivos y fuentes donde tengas autorización explícita.
- Backups: nunca sobrescribas data original sin una copia recuperable.
- Data governance: respeta privacidad, controles de acceso y clasificación de datos.
- Producción: nunca conectes scripts a fuentes reales sin revisión, aprobación y plan de reversa.
⚠️ Critical warning before running any script
Do not run R scripts against official files, real databases, institutional folders, SQL Server, Access, internal APIs, or sensitive datasets without formal authorization.
R can transform, summarize, model, and visualize thousands or millions of records quickly. A poorly tested analysis can produce wrong conclusions, overwrite files, expose sensitive data, or affect BI, audit, budget, or production decisions.
Mandatory training rule: start with synthetic data, then use a controlled copy, validate the result, and only then consider real data while following permissions, backups, change control, data governance, and cybersecurity protocols.
- Permissions: use only files and sources where you have explicit authorization.
- Backups: never overwrite original data without a recoverable copy.
- Data governance: respect privacy, access controls, and data classification.
- Production: never connect scripts to real sources without review, approval, and rollback planning.
Objetivo del Topic 1
Antes de limpiar o analizar, revisamos tipos de datos, valores faltantes y forma general del dataset.
Topic 1 Objective
Before cleaning or analyzing, inspect data types, missing values, and the overall shape of the dataset.
Ruta de trabajo
Todo se ejecuta dentro de una carpeta controlada:
Working folder
Everything runs inside a controlled folder:
base_path <- file.path(Sys.getenv("USERPROFILE"), "Documents", "AI Practical Training", "R", "Topic 1")Qué vamos a aprender
- Crear data sintética controlada.
- Leer y transformar datos en R.
- Aplicar una regla de análisis, limpieza o validación.
- Exportar resultados para revisión.
- Verificar el resultado antes de usar datos reales.
What you will learn
- Create controlled synthetic data.
- Read and transform data in R.
- Apply an analysis, cleaning, or validation rule.
- Export results for review.
- Verify the result before using real data.
Script 1 — Crear data sintética
Este script prepara datos de práctica para ejecutar el ejercicio sin tocar información real.
Script 1 — Create synthetic data
This script prepares practice data to run the exercise without touching real information.
# R Topic 1 - Script 1
# Create synthetic survey data
base_path <- file.path(Sys.getenv("USERPROFILE"), "Documents", "AI Practical Training", "R", "Topic 1")
data_path <- file.path(base_path, "Data")
dir.create(data_path, recursive = TRUE, showWarnings = FALSE)
data <- data.frame(
employee_id = c("10001", "10002", "10003", "10004"),
department = c("Finance", "HR", "IT", "Operations"),
score = c(85, 90, NA, 78),
response_date = c("2026-01-05", "2026-01-08", "2026-01-10", "2026-01-12")
)
write.csv(data, file.path(data_path, "survey_results.csv"), row.names = FALSE)
print(data)Script 2 — Ejecutar la acción principal
Este script aplica la lógica central del topic y genera el resultado principal del ejercicio.
Script 2 — Run the main action
This script applies the core topic logic and generates the main result of the exercise.
# R Topic 1 - Script 2
# Inspect table structure
library(readr)
library(dplyr)
base_path <- file.path(Sys.getenv("USERPROFILE"), "Documents", "AI Practical Training", "R", "Topic 1")
data_path <- file.path(base_path, "Data")
data <- read_csv(file.path(data_path, "survey_results.csv"), show_col_types = FALSE)
glimpse(data)
summary(data)
colSums(is.na(data))Script 3 — Verificar o reportar resultados
Este script confirma el resultado final o genera evidencia para revisión.
Script 3 — Verify or report results
This script confirms the final result or generates evidence for review.
# R Topic 1 - Script 3
# Export a simple structure report
library(readr)
library(dplyr)
base_path <- file.path(Sys.getenv("USERPROFILE"), "Documents", "AI Practical Training", "R", "Topic 1")
data_path <- file.path(base_path, "Data")
data <- read_csv(file.path(data_path, "survey_results.csv"), show_col_types = FALSE)
structure_report <- data.frame(
column_name = names(data),
class = sapply(data, function(x) paste(class(x), collapse = ", ")),
missing_values = sapply(data, function(x) sum(is.na(x)))
)
write.csv(structure_report, file.path(data_path, "structure_report.csv"), row.names = FALSE)
print(structure_report)Explicación simple del script
- base_path mantiene una ruta de práctica controlada.
- El Script 1 crea data sintética para evitar riesgos.
- El Script 2 aplica la lógica principal del topic.
- El Script 3 verifica resultados o deja evidencia.
- El resultado se guarda como CSV, imagen, Excel o reporte según el caso.
Simple script explanation
- base_path keeps a controlled practice path.
- Script 1 creates synthetic data to avoid risk.
- Script 2 applies the main topic logic.
- Script 3 verifies results or leaves evidence.
- The output is saved as CSV, image, Excel, or report depending on the case.
Ejemplo esperado
| Caso | Resultado |
|---|---|
| glimpse | data types |
| summary | basic statistics |
| missing count | data quality signal |
Expected example
| Case | Result |
|---|---|
| glimpse | data types |
| summary | basic statistics |
| missing count | data quality signal |
Conclusión
Antes de limpiar o analizar, revisamos tipos de datos, valores faltantes y forma general del dataset.
Conclusion
Before cleaning or analyzing, inspect data types, missing values, and the overall shape of the dataset.