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

Combine statistics of the 3 seasons

parent 094e6020
No related branches found
No related tags found
No related merge requests found
......@@ -27,11 +27,22 @@ aceptaTildes <- function(datos) {
return(datos)
}
decimalplaces <- function(x) {
ifelse(abs(x - round(x)) > .Machine$double.eps^0.5,
nchar(sub('^\\d+\\.', '', sub('0+$', '', as.character(x)))),
0)
}
#############
# LIBRERIAS #
#############
library(dplyr) # to inner join
library(tidyverse) # filter(), select(), contains()
############
# GLOBALES #
############
fusion <- 0
######################################
# LECTURA de DATOS #
......@@ -102,6 +113,7 @@ rowsPIn2CGlobal
####################################################
# Fusion de las muestras de jugadores en 2 equipos #
####################################################
if(fusion == 1) {
pos <- which(rowsPIn2CGlobal[,6] == "17-18")
r1 <- as.numeric(rowsPIn2CGlobal[pos, 2])
r2 <- as.numeric(rowsPIn2CGlobal[pos, 3])
......@@ -170,6 +182,7 @@ for (name in names) {
laLigaPlayers.1920 <- laLigaPlayers.1920[-auxPos,]
}
laLigaPlayers.1920 <- rbind(laLigaPlayers.1920, players)
}
##############
# INNER JOIN #
......@@ -256,3 +269,37 @@ Youssef <- t(Youssef)
jugador <- laLigaPlayers[rowsPIn2C[9,], ]
jugador <- jugador %>% select(contains(variables))
jugador <- t(jugador)
###################################################################
# Combinacion de estadisticas por temporada en una unica variable #
###################################################################
# Seleccionamos unicamente las variables del estudio
# No OLVIDAR "age.", "height.",
variables <- c("xa.", "passes_completed.", "passes.", "passes_pct.", "passes_total_distance.", "assisted_shots.", "passes_switches.",
"pass_targets.", "passes_received.", "passes_received_pct.", "passes_pressure.",
"xg.", "npxg.", "shots_total.", "shots_on_target.", "shots_on_target_pct.", "goals_per_shot.", "pens_made.", "pens_att.",
"dribbles.", "dribbles_completed.", "dribbles_completed_pct.", "goals_assists_per90.",
"sca_passes_dead.", "gca_passes_dead.", "sca_passes_live.", "gca_passes_live.", "sca_dribbles.", "gca_dribbles.", "sca_fouled.", "gca_fouled.",
"passes_intercepted.", "ball_recoveries.", "pressure_regains.", "fouls.", "tackles_won.", "tackles.", "aerials_won.", "aerials_lost.", "aerials_won_pct.",
"goals_against_per90_gk.", "pens_saved.", "pens_allowed.", "shots_on_target_against.", "saves.", "save_pct.")
globalColNames <- c()
for (variable in variables) {
variable <- gsub("\\.", "", variable)
globalColNames <- c(globalColNames, variable)
}
variablesWithSeason <- c(paste(variables, "1718", sep = ""), paste(variables, "1819", sep = ""), paste(variables, "1920", sep = ""))
trainStudyAux <- train %>% select(all_of(c("player", variablesWithSeason)))
trainStudy <- NULL
for (variable in variables) {
cat(variable)
aux <- trainStudyAux %>% select(contains(variable))
aux <- data.frame(lapply(aux, as.numeric))
if (dim(aux)[2] == 3) {
aux2 <- round(rowSums(aux)/3, decimalplaces(aux[1,1]))
}
trainStudy <- cbind(trainStudy, aux2)
}
trainStudy <- as_tibble(trainStudy)
names(trainStudy) <- globalColNames
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment