Skip to contents
library(ussie)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

ussie let’s you work with soccer data from the engsoccerdata package by making standard tibbles for each country

spain <- uss_make_matches(engsoccerdata::spain, "Spain")
glimpse(spain)
#> Rows: 23,915
#> Columns: 8
#> $ country       <chr> "Spain", "Spain", "Spain", "Spain", "Spain", "Spain", "S…
#> $ tier          <fct> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
#> $ season        <int> 1928, 1928, 1928, 1928, 1928, 1928, 1928, 1928, 1928, 19…
#> $ date          <date> 1929-02-10, 1929-02-10, 1929-02-10, 1929-02-10, 1929-02…
#> $ home          <chr> "Arenas de Getxo", "Espanyol Barcelona", "Real Madrid", …
#> $ visitor       <chr> "Atletico Madrid", "Real Union", "CE Europa", "Athletic …
#> $ goals_home    <int> 2, 3, 5, 1, 0, 1, 9, 0, 3, 5, 3, 3, 1, 0, 2, 1, 2, 3, 2,…
#> $ goals_visitor <int> 3, 2, 0, 1, 2, 2, 0, 3, 1, 2, 0, 1, 1, 4, 1, 2, 1, 0, 2,…

The function uss_get_matches() can get the data for a country

Get country data

uss_get_matches("italy") |> 
glimpse()
#> Rows: 25,404
#> Columns: 8
#> $ country       <chr> "Italy", "Italy", "Italy", "Italy", "Italy", "Italy", "I…
#> $ tier          <fct> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
#> $ season        <int> 1934, 1934, 1934, 1934, 1934, 1934, 1934, 1934, 1934, 19…
#> $ date          <date> 1934-09-30, 1934-09-30, 1934-09-30, 1934-09-30, 1934-09…
#> $ home          <chr> "Lazio Roma", "Torino FC", "Sampierdarenese", "SSC Napol…
#> $ visitor       <chr> "US Livorno", "Unione Triestina", "Bologna FC", "US Ales…
#> $ goals_home    <int> 6, 3, 2, 0, 4, 0, 3, 1, 1, 1, 2, 4, 2, 2, 3, 2, 2, 2, 0,…
#> $ goals_visitor <int> 1, 1, 1, 1, 1, 2, 0, 2, 1, 1, 1, 0, 2, 1, 1, 0, 1, 1, 1,…

We can add filtering conditions

uss_get_matches("england", season == 1966) |> 
  glimpse()
#> Rows: 2,028
#> Columns: 8
#> $ country       <chr> "England", "England", "England", "England", "England", "…
#> $ tier          <fct> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
#> $ season        <int> 1966, 1966, 1966, 1966, 1966, 1966, 1966, 1966, 1966, 19…
#> $ date          <date> 1966-08-27, 1966-09-17, 1966-12-03, 1967-02-04, 1967-04…
#> $ home          <chr> "Arsenal", "Arsenal", "Arsenal", "Arsenal", "Arsenal", "…
#> $ visitor       <chr> "Aston Villa", "Blackpool", "Burnley", "Chelsea", "Evert…
#> $ goals_home    <int> 1, 1, 0, 2, 3, 1, 0, 2, 1, 1, 1, 2, 1, 2, 1, 4, 3, 2, 0,…
#> $ goals_visitor <int> 0, 1, 0, 1, 1, 0, 1, 4, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 2,…

We can accumulate seasons

italy <- uss_get_matches("italy") |> uss_make_teams_matches()
uss_make_seasons_cumulative(italy) |> glimpse()
#> Rows: 50,808
#> Columns: 12
#> Groups: country, tier, season, team [1,516]
#> $ country       <chr> "Italy", "Italy", "Italy", "Italy", "Italy", "Italy", "I…
#> $ tier          <fct> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
#> $ season        <int> 1929, 1929, 1929, 1929, 1929, 1929, 1929, 1929, 1929, 19…
#> $ team          <chr> "AC Milan", "AC Milan", "AC Milan", "AC Milan", "AC Mila…
#> $ date          <date> 1929-10-06, 1929-10-13, 1929-10-20, 1929-10-27, 1929-11…
#> $ matches       <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1…
#> $ wins          <int> 1, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 5, 6, 7, 8, 8, 8, 8, 8,…
#> $ draws         <int> 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 4,…
#> $ losses        <int> 0, 0, 1, 1, 1, 2, 3, 3, 4, 4, 5, 5, 5, 5, 5, 6, 6, 7, 7,…
#> $ points        <int> 2, 4, 4, 6, 7, 7, 7, 9, 9, 11, 11, 12, 14, 16, 18, 18, 1…
#> $ goals_for     <int> 4, 5, 6, 9, 10, 11, 12, 14, 15, 20, 20, 21, 24, 25, 27, …
#> $ goals_against <int> 1, 1, 3, 4, 5, 7, 11, 12, 15, 17, 18, 19, 21, 21, 22, 24…
uss_make_seasons_final(italy) |> glimpse()
#> Rows: 1,516
#> Columns: 12
#> Groups: country, season, tier [85]
#> $ country       <chr> "Italy", "Italy", "Italy", "Italy", "Italy", "Italy", "I…
#> $ tier          <fct> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
#> $ season        <int> 1929, 1929, 1929, 1929, 1929, 1929, 1929, 1929, 1929, 19…
#> $ team          <chr> "Inter", "Genova 1893 Circolo del Calcio", "Juventus", "…
#> $ date          <date> 1930-07-06, 1930-07-06, 1930-07-06, 1930-07-06, 1930-07…
#> $ matches       <int> 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, …
#> $ wins          <int> 22, 20, 19, 16, 14, 15, 14, 14, 12, 13, 11, 11, 12, 12, …
#> $ draws         <int> 6, 8, 7, 7, 9, 6, 8, 8, 9, 7, 10, 8, 6, 5, 8, 6, 4, 8, 5…
#> $ losses        <int> 6, 6, 8, 11, 11, 13, 12, 12, 13, 14, 13, 15, 16, 17, 16,…
#> $ points        <int> 50, 48, 45, 39, 37, 36, 36, 36, 33, 33, 32, 30, 30, 29, …
#> $ goals_for     <int> 85, 63, 56, 52, 61, 73, 56, 55, 52, 45, 53, 48, 46, 51, …
#> $ goals_against <int> 38, 39, 31, 31, 51, 52, 46, 49, 60, 56, 48, 55, 64, 79, …