Created
June 12, 2020 22:54
-
-
Save robintux/e4067d98b43c8289a86a7dd44de6589b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ============================================================================= | |
# Abraham Zamudio [GMMNS] | |
# 2020/06/12 | |
# Lima-Peru | |
# ============================================================================= | |
# | |
# La data proviene de : | |
# https://www.osinergmin.gob.pe/seccion/institucional/regulacion-tarifaria/publicaciones/regulacion-tarifaria | |
# Explorar : | |
# INFORMACIÓN TÉCNICA COMERCIAL (BASE DE DATOS) | |
# | | |
# --- Sistema de Información Clientes Libres (SICLI) | |
# | | |
# ------ 2019 | |
# | | |
# --------- Tabla 4_Datos de Carga_2019 | |
# ------ 2018 | |
# | | |
# ---------Tabla 4_Datos de Carga_2018 | |
# | |
# Cargamos la data con las classes adecuadas | |
OsinergOct2k19 <- read.table("201910_TABLA4.txt", header = TRUE,sep = "\t", | |
colClasses = c("factor","factor","factor","character","character", "character", "character"), | |
) | |
# Verificamos la clase de cada una de las variables (columnas) | |
lapply(OsinergOct2k19, class) | |
# Cambiamos las comas (decimales) por puntos decimales mediante la creacion de nuevas columnas | |
# Estas columas nuevas son la representacion numerica (con punto decimal) de las columnas ENERG_ACTV y ENERG_REAC | |
OsinergOct2k19$ENERG_ACTV_Numeric <- as.numeric(sub(",", ".", OsinergOct2k19$ENERG_ACTV, fixed = TRUE)) | |
OsinergOct2k19$ENERG_REAC_Numeric <- as.numeric(sub(",", ".", OsinergOct2k19$ENERG_REAC, fixed = TRUE)) | |
# Verificamos la clase de cada una de las columnas (variables) | |
lapply(OsinergOct2k19, class) | |
# Eliminamos dos variables que ya o sirven en el formato incial | |
OsinergOct2k19 <- OsinergOct2k19[, -c(5,6)] | |
# Construimos una variable date/time | |
OsinergOct2k19$DateTime <- as.POSIXct(OsinergOct2k19$FECHA, format = "%d/%m/%y %H:%M:%S") | |
library(lubridate) | |
OsinergOct2k19$año <- year(OsinergOct2k19$DateTime) | |
OsinergOct2k19$mes <- month(OsinergOct2k19$DateTime) | |
OsinergOct2k19$dia <- day(OsinergOct2k19$DateTime) | |
OsinergOct2k19$hora <- hour(OsinergOct2k19$DateTime) | |
OsinergOct2k19$minuto <- minute(OsinergOct2k19$DateTime) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment