Skip to content
Snippets Groups Projects
Commit 735bfc93 authored by Mario Garrido Tapias's avatar Mario Garrido Tapias
Browse files

Correction of the inner join for players playing for 2 clubs in one season

parent 6f41e622
No related branches found
No related tags found
No related merge requests found
......@@ -63,11 +63,17 @@ rowsPIn2CGlobal <- c()
for (i in 1:length(allLaLigaPlayer)) {
repeatedPlayers <- which(duplicated(allLaLigaPlayer[[i]]$player) == TRUE)
playersIn2C <- allLaLigaPlayer[[i]]$player[repeatedPlayers]
nacionalitiesIn2C <- allLaLigaPlayer[[i]]$nationality[repeatedPlayers]
birthyearssIn2C <- allLaLigaPlayer[[i]]$birth_year[repeatedPlayers]
season <- switch (i, "17-18", "18-19", "19-20")
for (name in playersIn2C) {
rows <- which(allLaLigaPlayer[[i]]$player == name)
for (j in 1:length(playersIn2C)) {
rows <- which(allLaLigaPlayer[[i]]$player == playersIn2C[j] &
allLaLigaPlayer[[i]]$nationality == nacionalitiesIn2C[j] &
allLaLigaPlayer[[i]]$birth_year == birthyearssIn2C[j])
if(length(rows) > 1) {
teams <- c(allLaLigaPlayer[[i]]$squad[rows[1]], allLaLigaPlayer[[i]]$squad[rows[2]])
rowsPIn2CGlobal <- rbind(rowsPIn2CGlobal, c(name, rows, teams, season))
rowsPIn2CGlobal <- rbind(rowsPIn2CGlobal, c(playersIn2C[j], rows, teams, season))
}
}
}
colnames(rowsPIn2CGlobal) <- c("Jugador", "Fila 1", "Fila 2", "Equipo 1º", "Equipo 2º", "Temporada")
......@@ -148,9 +154,13 @@ laLigaPlayers.1920 <- rbind(laLigaPlayers.1920, players)
##############
# INNER JOIN #
##############
laLigaPlayers.1719 <- inner_join(laLigaPlayers.1718, laLigaPlayers.1819, by = c("player" = "player"), suffix = c(".1718", ".1819"))
auxLaLigaPlayers.1920 <- inner_join(laLigaPlayers.1920, laLigaPlayers.1920, by = c("player" = "player"), suffix = c(".1920", ".1920"))
laLigaPlayers <- inner_join(laLigaPlayers.1719, auxLaLigaPlayers.1920, by = c("player" = "player"))
laLigaPlayers <- inner_join(laLigaPlayers.1718, laLigaPlayers.1819,
by = c("player", "nationality", "birth_year"),
suffix = c("", ".1819")) %>%
inner_join(laLigaPlayers.1920,
by = c("player", "nationality", "birth_year"),
suffix = c(".1718", ".1920"))
# Veamos que jugadores jugaron en 2 CLUBES en algunas de las 3 temporadas contempladas
repeatedPlayers <- which(duplicated(laLigaPlayers$player) == TRUE)
......@@ -167,6 +177,6 @@ rowsPIn2C
# CONJUNTO de ENTRENAMIENTO # # CONJUNTO de TEST #
############################# ####################
set.seed(5682)
ind <- sample(2, nrow(laLigaPlayers), replace = TRUE, prob = c(0.8, 0.2))
ind <- sample(2, nrow(laLigaPlayers), replace = FALSE, prob = c(0.8, 0.2))
train <- laLigaPlayers[ind == 1, ]
test <- laLigaPlayers[ind == 2, ]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment