Explorar y generar tablas de distribución del conjunto de datas FIFA
Explorar determinando tablas y visualización de datos del conjunto de datos FIFA. Los datos se encuentran en la dirección: https://www.kaggle.com/karangadiya/fifa19?select=data.csv
El conjunto de datos data.csv incluye los atributos de los jugadores de la última edición de FIFA 2019 como Edad, Nacionalidad, Total, Potencial, Club, Valor, Salario, Pie preferido, Reputación internacional, Pie débil, Movimientos de habilidad, Ritmo de trabajo, Posición, Número de camiseta, Unido, Prestado desde, Contrato válido hasta , Altura, Peso, LS, ST, RS, LW, LF, CF, RF, RW, LAM, CAM, RAM, LM, LCM, CM, RCM, RM, LWB, LDM, CDM, RDM, RWB, LB, LCB , CB, RCB, RB, Centros, Remate, Rumbo, Precisión, Pases cortos, Voleas, Regate, Curva, FK Precisión, Pases largos, Control de balón, Aceleración, Sprint Velocidad, Agilidad, Reacciones, Equilibrio, Potencia de disparo, Salto, Resistencia, Fuerza, Tiros lejanos, Agresión , Intercepciones, Posicionamiento, Visión, Penalizaciones, Serenidad, Marcaje, Entrada de pie, Entrada deslizante, GKDiving, GKHandling, GKKicking, GKPositioning, GKReflexes y Cláusula de liberación.
library(readr)
library(dplyr)
library(lubridate)
library(fdth)
library(ggplot2)
library(fdth)
datos.FIFA <- read.csv("../datos/data FIFA.csv/data.csv", encoding = "UTF-8")
# head(datos.FIFA, 10)
head(datos.FIFA[,c(3,4,6,8,9,10,12,13,14,15,27,28)], 10)
## Name Age Nationality Overall Potential Club
## 1 L. Messi 31 Argentina 94 94 FC Barcelona
## 2 Cristiano Ronaldo 33 Portugal 94 94 Juventus
## 3 Neymar Jr 26 Brazil 92 93 Paris Saint-Germain
## 4 De Gea 27 Spain 91 93 Manchester United
## 5 K. De Bruyne 27 Belgium 91 92 Manchester City
## 6 E. Hazard 27 Belgium 91 91 Chelsea
## 7 L. Modric 32 Croatia 91 91 Real Madrid
## 8 L. Suárez 31 Uruguay 91 91 FC Barcelona
## 9 Sergio Ramos 32 Spain 91 91 Real Madrid
## 10 J. Oblak 25 Slovenia 90 93 Atlético Madrid
## Value Wage Special Preferred.Foot Height Weight
## 1 \200110.5M \200565K 2202 Left 5'7 159lbs
## 2 \20077M \200405K 2228 Right 6'2 183lbs
## 3 \200118.5M \200290K 2143 Right 5'9 150lbs
## 4 \20072M \200260K 1471 Right 6'4 168lbs
## 5 \200102M \200355K 2281 Right 5'11 154lbs
## 6 \20093M \200340K 2142 Right 5'8 163lbs
## 7 \20067M \200420K 2280 Right 5'8 146lbs
## 8 \20080M \200455K 2346 Right 6'0 190lbs
## 9 \20051M \200380K 2201 Right 6'0 181lbs
## 10 \20068M \20094K 1331 Right 6'2 192lbs
tail(datos.FIFA[,c(3,4,6,8,9,10,12,13,14,15,27,28)], 10)
## Name Age Nationality Overall Potential
## 18198 D. Holland 18 Republic of Ireland 47 61
## 18199 J. Livesey 18 England 47 70
## 18200 M. Baldisimo 18 Canada 47 69
## 18201 J. Young 18 Scotland 47 62
## 18202 D. Walsh 18 Republic of Ireland 47 68
## 18203 J. Lundstram 19 England 47 65
## 18204 N. Christoffersson 19 Sweden 47 63
## 18205 B. Worman 16 England 47 67
## 18206 D. Walker-Rice 17 England 47 66
## 18207 G. Nugent 16 England 46 66
## Club Value Wage Special Preferred.Foot Height Weight
## 18198 Cork City \20060K \2001K 1362 Right 5'10 141lbs
## 18199 Burton Albion \20060K \2001K 792 Right 5'11 154lbs
## 18200 Vancouver Whitecaps FC \20070K \2001K 1303 Right 5'6 150lbs
## 18201 Swindon Town \20060K \2001K 1203 Left 5'9 157lbs
## 18202 Waterford FC \20060K \2001K 1098 Left 6'1 168lbs
## 18203 Crewe Alexandra \20060K \2001K 1307 Right 5'9 134lbs
## 18204 Trelleborgs FF \20060K \2001K 1098 Right 6'3 170lbs
## 18205 Cambridge United \20060K \2001K 1189 Right 5'8 148lbs
## 18206 Tranmere Rovers \20060K \2001K 1228 Right 5'10 154lbs
## 18207 Tranmere Rovers \20060K \2001K 1321 Right 5'10 176lbs
Un proceso de limpieza de datos no sólo es encontrar basura como NA o valores vacíos null y saber que hacer con ellos, en muchos casos se requiere transformar variables, eliminar datos y agregar variables para dejar listos para realiar análisis de datos posteriores.
Agregar Pais de club dependiendo del pais de donse sea el club. PENDIENTE
Agregar Region de club: [“AFRICA”,“ASIA”,“OCEANIA”, “CONCACAF”, “EUROPA”,“SUDAMERICA”] PENDIENTE
Agregar variable estatura en metros numérica de Heigth
Agregar variable peso en kgs numérica de la variable Weight
Generar un conjunto de datos mas manipulable para resolver el análisis del CASO.
Cargar las funciones requeridas
source("../funciones/misfunciones.r")
#source("github.com/rpizarrog/carpeta/funciones/misfunciones.r")
datos.FIFA <- mutate(datos.FIFA, Estatura = festatura(Height), Pesokgs = flbskgs(Weight))
# datos.FIFA
datos.FIFA.reduc <- select(datos.FIFA, Name, Age, Nationality, Overall, Potential, Club, Value, Preferred.Foot, Position, Height, Weight, Estatura, Pesokgs)
head(datos.FIFA.reduc)
## Name Age Nationality Overall Potential Club
## 1 L. Messi 31 Argentina 94 94 FC Barcelona
## 2 Cristiano Ronaldo 33 Portugal 94 94 Juventus
## 3 Neymar Jr 26 Brazil 92 93 Paris Saint-Germain
## 4 De Gea 27 Spain 91 93 Manchester United
## 5 K. De Bruyne 27 Belgium 91 92 Manchester City
## 6 E. Hazard 27 Belgium 91 91 Chelsea
## Value Preferred.Foot Position Height Weight Estatura Pesokgs
## 1 \200110.5M Left RF 5'7 159lbs 1.70 72.12
## 2 \20077M Right ST 6'2 183lbs 1.88 83.01
## 3 \200118.5M Right LW 5'9 150lbs 1.75 68.04
## 4 \20072M Right GK 6'4 168lbs 1.93 76.20
## 5 \200102M Right RCM 5'11 154lbs 1.80 69.85
## 6 \20093M Right LF 5'8 163lbs 1.73 73.94
paste("Cantidad de registros", nrow(datos.FIFA.reduc))
## [1] "Cantidad de registros 18207"
paste("Cantidad de variables", ncol(datos.FIFA.reduc))
## [1] "Cantidad de variables 13"
str(datos.FIFA.reduc)
## 'data.frame': 18207 obs. of 13 variables:
## $ Name : chr "L. Messi" "Cristiano Ronaldo" "Neymar Jr" "De Gea" ...
## $ Age : int 31 33 26 27 27 27 32 31 32 25 ...
## $ Nationality : chr "Argentina" "Portugal" "Brazil" "Spain" ...
## $ Overall : int 94 94 92 91 91 91 91 91 91 90 ...
## $ Potential : int 94 94 93 93 92 91 91 91 91 93 ...
## $ Club : chr "FC Barcelona" "Juventus" "Paris Saint-Germain" "Manchester United" ...
## $ Value : chr "\200110.5M" "\20077M" "\200118.5M" "\20072M" ...
## $ Preferred.Foot: chr "Left" "Right" "Right" "Right" ...
## $ Position : chr "RF" "ST" "LW" "GK" ...
## $ Height : chr "5'7" "6'2" "5'9" "6'4" ...
## $ Weight : chr "159lbs" "183lbs" "150lbs" "168lbs" ...
## $ Estatura : num 1.7 1.88 1.75 1.93 1.8 1.73 1.73 1.83 1.83 1.88 ...
## $ Pesokgs : num 72.1 83 68 76.2 69.8 ...
nacion <- datos.FIFA.reduc %>%
group_by (Nationality) %>%
summarise(n = n())
nacion <- arrange(nacion, desc(n))
head(nacion, 10)
## # A tibble: 10 x 2
## Nationality n
## <chr> <int>
## 1 England 1662
## 2 Germany 1198
## 3 Spain 1072
## 4 Argentina 937
## 5 France 914
## 6 Brazil 827
## 7 Italy 702
## 8 Colombia 618
## 9 Japan 478
## 10 Netherlands 453
tail(nacion, 10)
## # A tibble: 10 x 2
## Nationality n
## <chr> <int>
## 1 New Caledonia 1
## 2 Oman 1
## 3 Palestine 1
## 4 Puerto Rico 1
## 5 Qatar 1
## 6 Rwanda 1
## 7 São Tomé & Príncipe 1
## 8 South Sudan 1
## 9 St Lucia 1
## 10 United Arab Emirates 1
ggplot(data = head(nacion, 10), aes(x = Nationality, y = n)) +
geom_bar(stat = "identity")
ggplot(data = tail(nacion, 10), aes(x = Nationality, y = n)) +
geom_bar(stat = "identity")
En este conjunto de datos, se identifican países que sólo tienen un jugador registrado, para algunos análisis ese número de jugadores no es representativo.
Interpretación: ¿Qué países tienen MÁS Y MENOS jugadores registrados y su relación con el poderío futbolístico que tienen?
age.nacion <- datos.FIFA.reduc %>%
group_by (Nationality) %>%
summarise(n = n(), media = round(mean(Age),2), mediana = round(median(Age),2))
age.nacion <- arrange(age.nacion, media)
head(age.nacion, 10)
## # A tibble: 10 x 4
## Nationality n media mediana
## <chr> <int> <dbl> <dbl>
## 1 Indonesia 1 17 17
## 2 Botswana 1 20 20
## 3 Rwanda 1 21 21
## 4 Tanzania 3 22 22
## 5 Zambia 9 22.2 21
## 6 Afghanistan 4 22.5 22
## 7 Chad 2 22.5 22.5
## 8 Antigua & Barbuda 4 22.8 22
## 9 Dominican Republic 2 23 23
## 10 Jordan 1 23 23
tail(age.nacion, 10)
## # A tibble: 10 x 4
## Nationality n media mediana
## <chr> <int> <dbl> <dbl>
## 1 Fiji 1 30 30
## 2 Guam 1 30 30
## 3 New Caledonia 1 30 30
## 4 Kuwait 1 31 31
## 5 Palestine 1 31 31
## 6 São Tomé & Príncipe 1 31 31
## 7 Trinidad & Tobago 4 31.8 28.5
## 8 Ethiopia 1 32 32
## 9 Puerto Rico 1 34 34
## 10 Oman 1 36 36
la.media<- round(mean(age.nacion$n),0)
la.media
## [1] 111
age.nacion.mean.n <- filter(age.nacion, n >= mean(age.nacion$n)) # Se puede utilizar la variable la.media
age.nacion.mean.n <- arrange(age.nacion.mean.n, media)
head(age.nacion.mean.n, 10)
## # A tibble: 10 x 4
## Nationality n media mediana
## <chr> <int> <dbl> <dbl>
## 1 Nigeria 121 23.1 22
## 2 Ghana 114 23.7 23
## 3 Netherlands 453 24 24
## 4 England 1662 24.0 23
## 5 Norway 341 24.0 24
## 6 Denmark 336 24.2 24
## 7 Mexico 366 24.3 23
## 8 Belgium 260 24.3 23
## 9 Germany 1198 24.3 24
## 10 Australia 236 24.4 24
tail(age.nacion.mean.n, 10)
## # A tibble: 10 x 4
## Nationality n media mediana
## <chr> <int> <dbl> <dbl>
## 1 Senegal 130 25.4 25.5
## 2 Serbia 126 25.6 26
## 3 Portugal 322 25.8 25
## 4 Italy 702 25.9 26
## 5 China PR 392 26.1 26
## 6 Japan 478 26.2 26
## 7 Argentina 937 26.2 26
## 8 Korea Republic 335 26.4 26
## 9 Uruguay 149 26.6 26
## 10 Brazil 827 27.6 27
ggplot(data = head(age.nacion.mean.n, 10), aes(Nationality, media)) +
geom_boxplot()
ggplot(data = tail(age.nacion.mean.n, 10), aes(Nationality, media)) +
geom_boxplot()
ggplot(data = datos.FIFA.reduc, aes(x = Nationality, y = Age)) +
geom_boxplot()
paises.top <- head(age.nacion.mean.n$Nationality, 10)
paises.top
## [1] "Nigeria" "Ghana" "Netherlands" "England" "Norway"
## [6] "Denmark" "Mexico" "Belgium" "Germany" "Australia"
datos.FIFA.paises.top.mean.n <- filter(datos.FIFA, Nationality %in% paises.top)
head(datos.FIFA.paises.top.mean.n[,c(3,4,6)])
## Name Age Nationality
## 1 K. De Bruyne 27 Belgium
## 2 E. Hazard 27 Belgium
## 3 T. Kroos 28 Germany
## 4 H. Kane 24 England
## 5 M. ter Stegen 26 Germany
## 6 T. Courtois 26 Belgium
ggplot(data = datos.FIFA.paises.top.mean.n, aes(x = Nationality, y = Age)) +
geom_boxplot()
datos.FIFA.reduc.merge <- merge(x = datos.FIFA.reduc, y=clubs.nation,
by.x = 'Club', by.y = 'club')
# tail(datos.FIFA.reduc.merge)
head(arrange(datos.FIFA.reduc.merge, desc(country)), 10)
## Club Name Age Nationality Overall Potential
## 1 Atlanta United M. Ambrose 24 United States 63 67
## 2 Atlanta United L. Kunga 19 United States 57 73
## 3 Atlanta United C. McCann 30 Republic of Ireland 66 66
## 4 Atlanta United F. Escobar 23 Argentina 67 74
## 5 Atlanta United A. Wheeler-Omiunu 23 United States 58 64
## 6 Atlanta United K. Kratz 31 Germany 67 67
## 7 Atlanta United E. Remedi 23 Argentina 71 79
## 8 Atlanta United J. Larentowicz 34 United States 68 68
## 9 Atlanta United J. Hernández 21 Venezuela 62 71
## 10 Atlanta United M. Robinson 21 United States 61 72
## Value Preferred.Foot Position Height Weight Estatura Pesokgs country
## 1 \200400K Left LB 5'9 165lbs 1.75 74.84 USA
## 2 \200220K Left LM 5'8 150lbs 1.73 68.04 USA
## 3 \200475K Left LB 6'1 165lbs 1.85 74.84 USA
## 4 \200900K Right RB 6'0 165lbs 1.83 74.84 USA
## 5 \200170K Right CM 5'9 174lbs 1.75 78.93 USA
## 6 \200675K Right CAM 5'8 159lbs 1.73 72.12 USA
## 7 \2003M Right LDM 5'7 159lbs 1.70 72.12 USA
## 8 \200270K Right CDM 6'1 174lbs 1.85 78.93 USA
## 9 \200400K Left LB 5'7 157lbs 1.70 71.21 USA
## 10 \200375K Right CB 6'2 185lbs 1.88 83.91 USA
## confederaion continent
## 1 CONMEBOL SOUTH AMERICA
## 2 CONMEBOL SOUTH AMERICA
## 3 CONMEBOL SOUTH AMERICA
## 4 CONMEBOL SOUTH AMERICA
## 5 CONMEBOL SOUTH AMERICA
## 6 CONMEBOL SOUTH AMERICA
## 7 CONMEBOL SOUTH AMERICA
## 8 CONMEBOL SOUTH AMERICA
## 9 CONMEBOL SOUTH AMERICA
## 10 CONMEBOL SOUTH AMERICA
datos.FIFA.only.club.coutry <- select(datos.FIFA.reduc.merge, Club, country)
datos.FIFA.only.club.coutry <- distinct(datos.FIFA.only.club.coutry)
head(datos.FIFA.only.club.coutry)
## Club country
## 1
## 2 SSV Jahn Regensburg
## 3 1. FC Heidenheim 1846
## 4 1. FC Kaiserslautern
## 5 1. FC Köln Germany
## 6 1. FC Magdeburg Germany
tabla <- data.frame(fdt_cat(datos.FIFA.only.club.coutry$country)) %>%
select (Category,f)
names(tabla) <- c("Country", "Equipos")
#tabla
tabla <- tabla[-1,] # Quita el primer registros que son los valores vacios
#o se puede hacer con
tabla <- filter(tabla, !Country == "")
head(tabla , 10)
## Country Equipos
## 1 England 48
## 2 Spain 28
## 3 USA 24
## 4 Italy 23
## 5 Germany 22
## 6 México 18
## 7 France 15
## 8 Argentina 12
## 9 China 10
## 10 Brazil 9
tail(tabla , 10)
## Country Equipos
## 23 South Corea 3
## 24 Turkey 3
## 25 Austria 2
## 26 Canada 2
## 27 Scotland 2
## 28 Ucrania 2
## 29 Australia 1
## 30 Corea 1
## 31 Denmark 1
## 32 Uruguay 1
ggplot(data = head(tabla,10), aes(Country, Equipos)) +
geom_col()
ggplot(data = tail(tabla,10), aes(Country, Equipos)) +
geom_col()
jug.por.club <- datos.FIFA.reduc.merge %>%
group_by (Club) %>%
summarise(n = n())
## `summarise()` ungrouping output (override with `.groups` argument)
jug.por.club
## # A tibble: 638 x 2
## Club n
## <chr> <int>
## 1 "" 241
## 2 " SSV Jahn Regensburg" 29
## 3 "1. FC Heidenheim 1846" 28
## 4 "1. FC Kaiserslautern" 26
## 5 "1. FC Köln" 28
## 6 "1. FC Magdeburg" 26
## 7 "1. FC Nürnberg" 29
## 8 "1. FC Union Berlin" 28
## 9 "1. FSV Mainz 05" 32
## 10 "Aalborg BK" 27
## # ... with 628 more rows
jug.por.club.top.ten <-head(arrange(jug.por.club, desc(n)),10)
jug.por.club.top.ten
## # A tibble: 10 x 2
## Club n
## <chr> <int>
## 1 "" 241
## 2 "Arsenal" 33
## 3 "AS Monaco" 33
## 4 "Atlético Madrid" 33
## 5 "Borussia Dortmund" 33
## 6 "Burnley" 33
## 7 "Cardiff City" 33
## 8 "CD Leganés" 33
## 9 "Chelsea" 33
## 10 "Eintracht Frankfurt" 33
jug.por.club.bot.ten <- tail(arrange(jug.por.club, desc(n)),10)
jug.por.club.bot.ten
## # A tibble: 10 x 2
## Club n
## <chr> <int>
## 1 Grêmio 20
## 2 Internacional 20
## 3 Paraná 20
## 4 Santos 20
## 5 Sport Club do Recife 20
## 6 Tromsø IL 20
## 7 Vitória 20
## 8 Limerick FC 19
## 9 Sligo Rovers 19
## 10 Derry City 18
datos.FIFA.reduc.merge.AS <- filter(datos.FIFA.reduc.merge, continent == 'SOUTH AMERICA')
mean(datos.FIFA.reduc.merge.AS$Value)
## Warning in mean.default(datos.FIFA.reduc.merge.AS$Value): argument is not
## numeric or logical: returning NA
## [1] NA
# Limpiar el atributo haciendo un casting