LABORATORIO NÚMERO 7
Hecho con gusto por Carla Carolina Pérez Hernández (UAEH)
Alumna: Ana Grisel Sanjuan Merida
Laboratorio - Gestión de datos de red - curaduría de datos
Objetivo: Explorar la organización de los datos
En este ejercicio vamos a:
Cargar nuestra matriz hipotética de datos
Transformar la matriz en un dataframe
Conventir un dataframe en matriz
MANUAL ECONGEO PÁGINA 2 PARA INSTALAR ECONGEO
install.packages(“devtools”)
library(devtools)
## Loading required package: usethis
devtools::install_github("PABalland/EconGeo", force = T)
## WARNING: Rtools is required to build R packages, but is not currently installed.
##
## Please download and install Rtools 4.2 from https://cran.r-project.org/bin/windows/Rtools/ or https://www.r-project.org/nosvn/winutf8/ucrt3/.
## Downloading GitHub repo PABalland/EconGeo@HEAD
##
## ── R CMD build ─────────────────────────────────────────────────────────────────
## WARNING: Rtools is required to build R packages, but is not currently installed.
##
## Please download and install Rtools 4.2 from https://cran.r-project.org/bin/windows/Rtools/ or https://www.r-project.org/nosvn/winutf8/ucrt3/.
##
checking for file 'C:\Users\Lenovo\AppData\Local\Temp\RtmpYRYCKF\remotes4f242dfe2588\PABalland-EconGeo-420c3c5/DESCRIPTION' ...
checking for file 'C:\Users\Lenovo\AppData\Local\Temp\RtmpYRYCKF\remotes4f242dfe2588\PABalland-EconGeo-420c3c5/DESCRIPTION' ...
✔ checking for file 'C:\Users\Lenovo\AppData\Local\Temp\RtmpYRYCKF\remotes4f242dfe2588\PABalland-EconGeo-420c3c5/DESCRIPTION' (996ms)
##
─ preparing 'EconGeo': (938ms)
## checking DESCRIPTION meta-information ...
✔ checking DESCRIPTION meta-information
##
─ checking for LF line-endings in source and make files and shell scripts
##
─ checking for empty or unneeded directories
##
Omitted 'LazyData' from DESCRIPTION
##
─ building 'EconGeo_1.3.tar.gz'
##
##
## Installing package into 'C:/Users/Lenovo/AppData/Local/R/win-library/4.2'
## (as 'lib' is unspecified)
INICIO DE LABORATORIO 7
Gestión de datos de red
Cargar la librería
library (EconGeo)
##
## Please cite EconGeo in publications as:
## Balland, P.A. (2017) Economic Geography in R: Introduction to the EconGeo Package, Papers in Evolutionary Economic Geography, 17 (09): 1-75
Obtener la matriz
M = as.matrix(
read.csv("https://raw.githubusercontent.com/PABalland/ON/master/amz.csv" ,
sep = ",",
header = T,
row.names = 1))
Para visualizar solo se pone la M. Es una matriz de ventaja comparativa revelada (VCR o RCA).
M
## Tie Book Surfboard Short Water
## Pierre 0 0 1 1 1
## Ron 1 1 0 0 1
## Andrea 1 1 0 0 1
## David 0 0 1 1 1
## Cesar 1 1 0 0 1
## Paula 1 1 1 1 1
Ejemplo de una matriz de RCA con personas y productos/ paises y productos-industrias. Se visualiza en la pestaña “Help” de las visulizaciones (es la analítica visual)
?RCA
## starting httpd help server ... done
Enlistar las aristas EL (edge list). Es el listado de variables organizados en un dataframe. Extraer la lista con “get list” de la matriz “M”. El nombre de las columnas (colnames) son “clientes”, “productos” y “contenido de la matriz”. Generar el dataframe permite hacer estudios estadísticos y econométricos.
EL = get.list (M)
colnames (EL) = c("Customer" , "Product" , "Count")
La forma más usual de encontrar los datos
EL
## Customer Product Count
## 1 Pierre Tie 0
## 2 Ron Tie 1
## 3 Andrea Tie 1
## 4 David Tie 0
## 5 Cesar Tie 1
## 6 Paula Tie 1
## 7 Pierre Book 0
## 8 Ron Book 1
## 9 Andrea Book 1
## 10 David Book 0
## 11 Cesar Book 1
## 12 Paula Book 1
## 13 Pierre Surfboard 1
## 14 Ron Surfboard 0
## 15 Andrea Surfboard 0
## 16 David Surfboard 1
## 17 Cesar Surfboard 0
## 18 Paula Surfboard 1
## 19 Pierre Short 1
## 20 Ron Short 0
## 21 Andrea Short 0
## 22 David Short 1
## 23 Cesar Short 0
## 24 Paula Short 1
## 25 Pierre Water 1
## 26 Ron Water 1
## 27 Andrea Water 1
## 28 David Water 1
## 29 Cesar Water 1
## 30 Paula Water 1
Crear matriz mediante MM (será la matriz transformada). El input será el listado que se acaba de obtener (el dataframe: la lista). Para correrlo, seleccionar desde MM y hasta matriz (la indicación descrita). Convierte un dataframe(lista) en matriz.
MM = get.matrix(EL)
##
## Attaching package: 'Matrix'
## The following object is masked from 'package:reshape':
##
## expand
Para visualizar la matriz transformada que se acaba de creear, corremos MM. Esta matriz es funcional para operaciones algebráicas
MM
## Tie Book Surfboard Short Water
## Pierre 0 0 1 1 1
## Ron 1 1 0 0 1
## Andrea 1 1 0 0 1
## David 0 0 1 1 1
## Cesar 1 1 0 0 1
## Paula 1 1 1 1 1
Edge list (lista de aristas(source-target—-adyacentes-mis 3 columnas)
EL
## Customer Product Count
## 1 Pierre Tie 0
## 2 Ron Tie 1
## 3 Andrea Tie 1
## 4 David Tie 0
## 5 Cesar Tie 1
## 6 Paula Tie 1
## 7 Pierre Book 0
## 8 Ron Book 1
## 9 Andrea Book 1
## 10 David Book 0
## 11 Cesar Book 1
## 12 Paula Book 1
## 13 Pierre Surfboard 1
## 14 Ron Surfboard 0
## 15 Andrea Surfboard 0
## 16 David Surfboard 1
## 17 Cesar Surfboard 0
## 18 Paula Surfboard 1
## 19 Pierre Short 1
## 20 Ron Short 0
## 21 Andrea Short 0
## 22 David Short 1
## 23 Cesar Short 0
## 24 Paula Short 1
## 25 Pierre Water 1
## 26 Ron Water 1
## 27 Andrea Water 1
## 28 David Water 1
## 29 Cesar Water 1
## 30 Paula Water 1
Matriz de adyancencia
get.matrix(EL)
## Tie Book Surfboard Short Water
## Pierre 0 0 1 1 1
## Ron 1 1 0 0 1
## Andrea 1 1 0 0 1
## David 0 0 1 1 1
## Cesar 1 1 0 0 1
## Paula 1 1 1 1 1
Buscar Andrea. En la ventana de Entorno de variables (Environment) damos doble clic en EL para ver la tabla. En el buscador (donde está la lupa) escribimos Andrea y nos mostrará solo los resultados de ese cliente. Esta es una manera de filtrar la información.
Otra manera es generar un objeto x que sea una subtabla que contenga el dataframe del producto denominado corbata “Tie”.
x = subset (EL, Product =="Tie")
Para sisualizarlo el comando es x. Se ven todos los clientes pero solo el producto seleccionado.
x
## Customer Product Count
## 1 Pierre Tie 0
## 2 Ron Tie 1
## 3 Andrea Tie 1
## 4 David Tie 0
## 5 Cesar Tie 1
## 6 Paula Tie 1