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 european football data from the engsoccerdata package by making standard tibles 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,…

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)
#> # A tibble: 50,808 × 12
#> # Groups:   country, tier, season, team [1,516]
#>    country tier  season team     date       matches  wins draws losses points
#>    <chr>   <fct>  <int> <chr>    <date>       <int> <int> <int>  <int>  <int>
#>  1 Italy   1       1929 AC Milan 1929-10-06       1     1     0      0      2
#>  2 Italy   1       1929 AC Milan 1929-10-13       2     2     0      0      4
#>  3 Italy   1       1929 AC Milan 1929-10-20       3     2     0      1      4
#>  4 Italy   1       1929 AC Milan 1929-10-27       4     3     0      1      6
#>  5 Italy   1       1929 AC Milan 1929-11-03       5     3     1      1      7
#>  6 Italy   1       1929 AC Milan 1929-11-10       6     3     1      2      7
#>  7 Italy   1       1929 AC Milan 1929-11-17       7     3     1      3      7
#>  8 Italy   1       1929 AC Milan 1929-11-24       8     4     1      3      9
#>  9 Italy   1       1929 AC Milan 1929-12-08       9     4     1      4      9
#> 10 Italy   1       1929 AC Milan 1929-12-15      10     5     1      4     11
#> # … with 50,798 more rows, and 2 more variables: goals_for <int>,
#> #   goals_against <int>
uss_make_seasons_final(italy)
#> # A tibble: 1,516 × 12
#> # Groups:   country, season, tier [85]
#>    country tier  season team        date       matches  wins draws losses points
#>    <chr>   <fct>  <int> <chr>       <date>       <int> <int> <int>  <int>  <int>
#>  1 Italy   1       1929 Inter       1930-07-06      34    22     6      6     50
#>  2 Italy   1       1929 Genova 189… 1930-07-06      34    20     8      6     48
#>  3 Italy   1       1929 Juventus    1930-07-06      34    19     7      8     45
#>  4 Italy   1       1929 Torino FC   1930-07-06      34    16     7     11     39
#>  5 Italy   1       1929 SSC Napoli  1930-07-06      34    14     9     11     37
#>  6 Italy   1       1929 AS Roma     1930-07-06      34    15     6     13     36
#>  7 Italy   1       1929 Bologna FC  1930-07-06      34    14     8     12     36
#>  8 Italy   1       1929 US Alessan… 1930-07-06      34    14     8     12     36
#>  9 Italy   1       1929 Pro Vercel… 1930-07-06      34    12     9     13     33
#> 10 Italy   1       1929 Brescia Ca… 1930-07-06      34    13     7     14     33
#> # … with 1,506 more rows, and 2 more variables: goals_for <int>,
#> #   goals_against <int>