The main function gets the club rankings, while others will use dplyr to get by-country and by-league averages.
get_country_averages(rankings_2018)
# A tibble: 18 x 6
country off_rating def_rating spi n_teams rank
<chr> <dbl> <dbl> <dbl> <int> <dbl>
1 Spain 2.02 0.79 71.6 20 1
2 Germany 2.02 0.906 69.1 18 2
3 England 1.88 0.915 65.1 20 3
4 Italy 1.76 0.96 63.1 20 4
5 France 1.64 0.995 59.7 20 5
6 Russia 1.38 0.988 54.7 16 6
7 Brazil 1.27 1.20 47.0 24 7
8 Portugal 1.32 1.24 46.9 18 8
9 Turkey 1.41 1.39 46.3 18 9
10 Argentina 1.17 1.16 45.4 28 10
11 Switzerland 1.47 1.5 45.3 10 11
12 Mexico 1.24 1.38 42.2 18 12
13 Austria 1.36 1.53 41.9 10 13
14 Netherlands 1.46 1.74 40.3 18 14
15 Sweden 1.11 1.66 34.0 19 15
16 USA 1.11 1.75 32.1 23 16
17 Norway 1.06 1.8 30.6 19 17
18 Scotland 0.908 1.74 28.2 12 18
get_league_averages(rankings_2018)
# A tibble: 23 x 7
country league off_rating def_rating spi n_teams rank
<chr> <chr> <dbl> <dbl> <dbl> <int> <dbl>
1 Spain La Liga 2.02 0.79 71.6 20 1
2 Germany Bundesliga 2.02 0.906 69.1 18 2
3 England Premier League 1.88 0.915 65.1 20 3
4 Italy Serie A 1.76 0.96 63.1 20 4
5 France Ligue 1 1.64 0.995 59.7 20 5
6 Russia Premier League 1.38 0.988 54.7 16 6
7 Brazil Brasileirão 1.27 1.20 47.0 24 7
8 Portugal Primeira Liga 1.32 1.24 46.9 18 8
9 Turkey Süper Lig 1.41 1.39 46.3 18 9
10 Argentina Superliga 1.17 1.16 45.4 28 10
# ... with 13 more rows