Skip to content

Instantly share code, notes, and snippets.

@knbknb
Last active October 7, 2018 12:01
Show Gist options
  • Save knbknb/0695fc32099958f373fa6e69475e1c53 to your computer and use it in GitHub Desktop.
Save knbknb/0695fc32099958f373fa6e69475e1c53 to your computer and use it in GitHub Desktop.
Input files for "Why I Think Atletico De Madrid Will Win 2013/14 Spanish Liga Of Football", by A.S. Chinchon, 2014
home.team score away.team round score_home score_visiting home.wins away.wins
Athletic 4-2 Valladolid 20 4 2 3 0
Atletico 1-1 Sevilla 20 1 1 1 1
Betis 0-5 R. Madrid 20 0 5 0 3
Espanyol 1-0 Celta 20 1 0 3 0
Villarreal 2-0 Almeria 20 2 0 3 0
Malaga 0-0 Valencia 20 0 0 1 1
Elche 2-0 Rayo 20 2 0 3 0
Getafe 2-2 R. Sociedad 20 2 2 1 1
Levante 1-1 Barcelona 20 1 1 1 1
Granada 0-0 Osasuna 20 0 0 1 1
Athletic 6-1 Almeria 19 6 1 3 0
Atletico 0-0 Barcelona 19 0 0 1 1
Betis 1-2 Osasuna 19 1 2 0 3
Celta 2-1 Valencia 19 2 1 3 0
Espanyol 0-1 R. Madrid 19 0 1 0 3
Villarreal 5-1 R. Sociedad 19 5 1 3 0
Elche 1-1 Sevilla 19 1 1 1 1
Getafe 0-1 Rayo 19 0 1 0 3
Levante 1-0 Malaga 19 1 0 3 0
Granada 4-0 Valladolid 19 4 0 3 0
Barcelona 4-0 Elche 18 4 0 3 0
R. Madrid 3-0 Celta 18 3 0 3 0
R. Sociedad 2-0 Athletic 18 2 0 3 0
Valencia 2-0 Levante 18 2 0 3 0
Valladolid 0-0 Betis 18 0 0 1 1
Rayo 2-5 Villarreal 18 2 5 0 3
Malaga 0-1 Atletico 18 0 1 0 3
Sevilla 3-0 Getafe 18 3 0 3 0
Osasuna 1-0 Espanyol 18 1 0 3 0
Almeria 3-0 Granada 18 3 0 3 0
Athletic 2-1 Rayo 17 2 1 3 0
Atletico 3-2 Levante 17 3 2 3 0
Betis 0-1 Almeria 17 0 1 0 3
Celta 1-1 Osasuna 17 1 1 1 1
Espanyol 4-2 Valladolid 17 4 2 3 0
Valencia 2-3 R. Madrid 17 2 3 0 3
Villarreal 1-2 Sevilla 17 1 2 0 3
Elche 0-1 Malaga 17 0 1 0 3
Getafe 2-5 Barcelona 17 2 5 0 3
Granada 1-3 R. Sociedad 17 1 3 0 3
Atletico 3-0 Valencia 16 3 0 3 0
Barcelona 2-1 Villarreal 16 2 1 3 0
R. Sociedad 5-1 Betis 16 5 1 3 0
Valladolid 3-0 Celta 16 3 0 3 0
Rayo 0-2 Granada 16 0 2 0 3
Malaga 1-0 Getafe 16 1 0 3 0
Sevilla 1-1 Athletic 16 1 1 1 1
Osasuna 2-2 R. Madrid 16 2 2 1 1
Levante 2-1 Elche 16 2 1 3 0
Almeria 0-0 Espanyol 16 0 0 1 1
Athletic 1-0 Barcelona 15 1 0 3 0
Betis 2-2 Rayo 15 2 2 1 1
Celta 3-1 Almeria 15 3 1 3 0
Espanyol 1-2 R. Sociedad 15 1 2 0 3
R. Madrid 4-0 Valladolid 15 4 0 3 0
Valencia 3-0 Osasuna 15 3 0 3 0
Villarreal 1-1 Malaga 15 1 1 1 1
Elche 0-2 Atletico 15 0 2 0 3
Getafe 1-0 Levante 15 1 0 3 0
Granada 1-2 Sevilla 15 1 2 0 3
Atletico 7-0 Getafe 14 7 0 3 0
Barcelona 4-0 Granada 14 4 0 3 0
R. Sociedad 4-3 Celta 14 4 3 3 0
Valladolid 0-1 Osasuna 14 0 1 0 3
Rayo 1-4 Espanyol 14 1 4 0 3
Malaga 1-2 Athletic 14 1 2 0 3
Sevilla 4-0 Betis 14 4 0 3 0
Elche 2-1 Valencia 14 2 1 3 0
Levante 0-3 Villarreal 14 0 3 0 3
Almeria 0-5 R. Madrid 14 0 5 0 3
Athletic 2-1 Levante 13 2 1 3 0
Betis 1-4 Barcelona 13 1 4 0 3
Celta 0-2 Rayo 13 0 2 0 3
Espanyol 1-3 Sevilla 13 1 3 0 3
R. Madrid 5-1 R. Sociedad 13 5 1 3 0
Valencia 2-2 Valladolid 13 2 2 1 1
Villarreal 1-1 Atletico 13 1 1 1 1
Osasuna 0-1 Almeria 13 0 1 0 3
Getafe 1-1 Elche 13 1 1 1 1
Granada 3-1 Malaga 13 3 1 3 0
Atletico 2-0 Athletic 12 2 0 3 0
Barcelona 1-0 Espanyol 12 1 0 3 0
R. Sociedad 5-0 Osasuna 12 5 0 3 0
Rayo 2-3 R. Madrid 12 2 3 0 3
Malaga 3-2 Betis 12 3 2 3 0
Sevilla 0-1 Celta 12 0 1 0 3
Elche 0-1 Villarreal 12 0 1 0 3
Getafe 0-1 Valencia 12 0 1 0 3
Levante 0-1 Granada 12 0 1 0 3
Almeria 1-0 Valladolid 12 1 0 3 0
Athletic 2-2 Elche 11 2 2 1 1
Betis 0-0 Levante 11 0 0 1 1
Celta 0-3 Barcelona 11 0 3 0 3
Espanyol 0-0 Malaga 11 0 0 1 1
R. Madrid 7-3 Sevilla 11 7 3 3 0
Valencia 1-2 Almeria 11 1 2 0 3
Valladolid 2-2 R. Sociedad 11 2 2 1 1
Villarreal 0-2 Getafe 11 0 2 0 3
Osasuna 3-1 Rayo 11 3 1 3 0
Granada 1-2 Atletico 11 1 2 0 3
Atletico 5-0 Betis 10 5 0 3 0
Barcelona 2-1 R. Madrid 10 2 1 3 0
R. Sociedad 3-0 Almeria 10 3 0 3 0
Villarreal 4-1 Valencia 10 4 1 3 0
Rayo 0-3 Valladolid 10 0 3 0 3
Malaga 0-5 Celta 10 0 5 0 3
Sevilla 2-1 Osasuna 10 2 1 3 0
Elche 0-1 Granada 10 0 1 0 3
Getafe 0-1 Athletic 10 0 1 0 3
Levante 3-0 Espanyol 10 3 0 3 0
Athletic 2-0 Villarreal 9 2 0 3 0
Betis 1-2 Elche 9 1 2 0 3
Celta 0-1 Levante 9 0 1 0 3
Espanyol 1-0 Atletico 9 1 0 3 0
R. Madrid 2-0 Malaga 9 2 0 3 0
Valencia 1-2 R. Sociedad 9 1 2 0 3
Valladolid 2-2 Sevilla 9 2 2 1 1
Osasuna 0-0 Barcelona 9 0 0 1 1
Granada 0-2 Getafe 9 0 2 0 3
Almeria 0-1 Rayo 9 0 1 0 3
Athletic 1-1 Valencia 8 1 1 1 1
Atletico 2-1 Celta 8 2 1 3 0
Barcelona 4-1 Valladolid 8 4 1 3 0
Villarreal 3-0 Granada 8 3 0 3 0
Rayo 1-0 R. Sociedad 8 1 0 3 0
Malaga 0-1 Osasuna 8 0 1 0 3
Sevilla 2-1 Almeria 8 2 1 3 0
Elche 2-1 Espanyol 8 2 1 3 0
Getafe 3-1 Betis 8 3 1 3 0
Levante 2-3 R. Madrid 8 2 3 0 3
Betis 1-0 Villarreal 7 1 0 3 0
Celta 0-1 Elche 7 0 1 0 3
Espanyol 0-2 Getafe 7 0 2 0 3
R. Madrid 0-1 Atletico 7 0 1 0 3
R. Sociedad 1-1 Sevilla 7 1 1 1 1
Valencia 1-0 Rayo 7 1 0 3 0
Valladolid 2-2 Malaga 7 2 2 1 1
Osasuna 0-1 Levante 7 0 1 0 3
Granada 2-0 Athletic 7 2 0 3 0
Almeria 0-2 Barcelona 7 0 2 0 3
Athletic 2-1 Betis 6 2 1 3 0
Atletico 2-1 Osasuna 6 2 1 3 0
Barcelona 4-1 R. Sociedad 6 4 1 3 0
Villarreal 2-1 Espanyol 6 2 1 3 0
Malaga 2-0 Almeria 6 2 0 3 0
Sevilla 4-1 Rayo 6 4 1 3 0
Elche 1-2 R. Madrid 6 1 2 0 3
Getafe 2-0 Celta 6 2 0 3 0
Levante 1-1 Valladolid 6 1 1 1 1
Granada 0-1 Valencia 6 0 1 0 3
Betis 0-0 Granada 5 0 0 1 1
Celta 0-0 Villarreal 5 0 0 1 1
Espanyol 3-2 Athletic 5 3 2 3 0
R. Madrid 4-1 Getafe 5 4 1 3 0
R. Sociedad 0-0 Malaga 5 0 0 1 1
Valencia 3-1 Sevilla 5 3 1 3 0
Valladolid 0-2 Atletico 5 0 2 0 3
Rayo 0-4 Barcelona 5 0 4 0 3
Osasuna 2-1 Elche 5 2 1 3 0
Almeria 2-2 Levante 5 2 2 1 1
Athletic 3-2 Celta 4 3 2 3 0
Atletico 4-2 Almeria 4 4 2 3 0
Barcelona 3-2 Sevilla 4 3 2 3 0
Betis 3-1 Valencia 4 3 1 3 0
Villarreal 2-2 R. Madrid 4 2 2 1 1
Malaga 5-0 Rayo 4 5 0 3 0
Elche 0-0 Valladolid 4 0 0 1 1
Getafe 2-1 Osasuna 4 2 1 3 0
Levante 0-0 R. Sociedad 4 0 0 1 1
Granada 0-1 Espanyol 4 0 1 0 3
Celta 1-1 Granada 3 1 1 1 1
Espanyol 0-0 Betis 3 0 0 1 1
R. Madrid 3-1 Athletic 3 3 1 3 0
R. Sociedad 1-2 Atletico 3 1 2 0 3
Valencia 2-3 Barcelona 3 2 3 0 3
Valladolid 1-0 Getafe 3 1 0 3 0
Rayo 1-2 Levante 3 1 2 0 3
Sevilla 2-2 Malaga 3 2 2 1 1
Osasuna 0-3 Villarreal 3 0 3 0 3
Almeria 2-2 Elche 3 2 2 1 1
Athletic 2-0 Osasuna 2 2 0 3 0
Atletico 5-0 Rayo 2 5 0 3 0
Betis 1-2 Celta 2 1 2 0 3
Espanyol 3-1 Valencia 2 3 1 3 0
Villarreal 2-1 Valladolid 2 2 1 3 0
Malaga 0-1 Barcelona 2 0 1 0 3
Elche 1-1 R. Sociedad 2 1 1 1 1
Getafe 2-2 Almeria 2 2 2 1 1
Levante 0-0 Sevilla 2 0 0 1 1
Granada 0-1 R. Madrid 2 0 1 0 3
Barcelona 7-0 Levante 1 7 0 3 0
Celta 2-2 Espanyol 1 2 2 1 1
R. Madrid 2-1 Betis 1 2 1 3 0
R. Sociedad 2-0 Getafe 1 2 0 3 0
Valencia 1-0 Malaga 1 1 0 3 0
Valladolid 1-2 Athletic 1 1 2 0 3
Rayo 3-0 Elche 1 3 0 3 0
Sevilla 1-3 Atletico 1 1 3 0 3
Osasuna 1-2 Granada 1 1 2 0 3
Almeria 2-3 Villarreal 1 2 3 0 3
# code from https://aschinchon.wordpress.com/2016/01/20/a-checkpoint-of-spanish-football-league/
# worked for me on 20180225
library(rvest)
library(stringr)
library(dplyr)
nseasons=20 # should be named 'matchdays'
results=data.frame()
for (i in 1:nseasons)
{
webpage=paste0("http://www.marca.com/estadisticas/futbol/primera/2013_14/jornada_",i,"/")
html(webpage) %>%
html_nodes("table") %>%
.[[1]] %>%
html_table(header=FALSE, fill=TRUE) %>%
mutate(X4=i) %>%
rbind(results)->results
}
colnames(results)=c("home", "score", "visiting", "season")
results <- results %>%
mutate(home = iconv(home, from="UTF8",to="ASCII//TRANSLIT"),
visiting = iconv(visiting, from="UTF8",to="ASCII//TRANSLIT")) %>%
#filter(grepl("-", score)) %>%
mutate(score=replace(score, score=="18:30 - 17/02/2016", "0-2")) %>% # resultado fake para el Barcelona
mutate(score_home = as.numeric(str_split_fixed(score, "-", 2)[,1])) %>%
mutate(score_visiting = as.numeric(str_split_fixed(score, "-", 2)[,2])) %>%
mutate(points_home =ifelse(score_home > score_visiting, 3, ifelse(score_home < score_visiting, 0, 1))) %>%
mutate(points_visiting =ifelse(score_home > score_visiting, 0, ifelse(score_home < score_visiting, 3, 1))) -> data
#########
# added, knbknb 2018
# make colnames consistent with usage in A.R. Chinchon's blogpost from 2014
# "Why I Think Atletico De Madrid Will Win 2013/14 Spanish Liga Of Football"
football <- results %>%
dplyr::rename(round = "season",
"home.team" = "home", "away.team" = "visiting",
"home.wins" = "points_home", "away.wins" = "points_visiting"
)
write.csv("CalendarioLiga2013-14.csv",
x=football, row.names = FALSE)
# Attention: Team names are still slightly inconsistent, example: (in blogpost) "At. Madrid" <=> "Atletico" (marca.com data)
@knbknb
Copy link
Author

knbknb commented Oct 7, 2018

# header of https://gist.github.com/knbknb/0695fc32099958f373fa6e69475e1c53#file-calendarioliga2013-14-csv
# see https://gist.github.com/knbknb/
#
# input file for blogpost --Why I Think Atletico De Madrid Will Win 2013/14 Spanish Liga Of Football--
# by A.S. Chinchon 2014
# https://fronkonstin.com/2014/01/20/why-i-think-atletico-de-madrid-will-win-201314-spanish-liga-of-football/
# created by re-using rvest R code from https://aschinchon.wordpress.com/2016/01/20/a-checkpoint-of-spanish-football-league/
#

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment