Import data
# excel file
Prem <- read_excel("../00_data/Premier League Match Data 21-22.xlsx")
Filter rows
filter(Prem, HomeTeam == "Arsenal")
## # A tibble: 19 × 22
## Date HomeTeam AwayTeam FTHG FTAG FTR HTHG HTAG HTR Referee HS
## <chr> <chr> <chr> <dbl> <dbl> <chr> <dbl> <dbl> <chr> <chr> <dbl>
## 1 22/08/20… Arsenal Chelsea 0 2 A 0 2 A P Tier… 6
## 2 44509 Arsenal Norwich 1 0 H 0 0 D M Oliv… 30
## 3 26/09/20… Arsenal Tottenh… 3 1 H 3 0 H C Paws… 12
## 4 18/10/20… Arsenal Crystal… 2 2 D 1 0 H M Dean 17
## 5 22/10/20… Arsenal Aston V… 3 1 H 2 0 H C Paws… 22
## 6 44388 Arsenal Watford 1 0 H 0 0 D K Frie… 14
## 7 27/11/20… Arsenal Newcast… 2 0 H 0 0 D S Attw… 24
## 8 44512 Arsenal Southam… 3 0 H 2 0 H J Gill… 15
## 9 15/12/20… Arsenal West Ham 2 0 H 0 0 D A Tayl… 21
## 10 44562 Arsenal Man City 1 2 A 1 0 H S Attw… 7
## 11 23/01/20… Arsenal Burnley 0 0 D 0 0 D D Coote 20
## 12 19/02/20… Arsenal Brentfo… 2 1 H 0 0 D J Moss 24
## 13 24/02/20… Arsenal Wolves 2 1 H 0 1 A M Atki… 26
## 14 13/03/20… Arsenal Leicest… 2 0 H 1 0 H A Tayl… 21
## 15 16/03/20… Arsenal Liverpo… 0 2 A 0 0 D A Marr… 9
## 16 44808 Arsenal Brighton 1 2 A 0 1 A D Coote 20
## 17 23/04/20… Arsenal Man Uni… 3 1 H 2 1 H C Paws… 14
## 18 44778 Arsenal Leeds 2 1 H 2 0 H C Kava… 19
## 19 22/05/20… Arsenal Everton 5 1 H 2 1 H A Marr… 26
## # ℹ 11 more variables: AS <dbl>, HST <dbl>, AST <dbl>, HF <dbl>, AF <dbl>,
## # HC <dbl>, AC <dbl>, HY <dbl>, AY <dbl>, HR <dbl>, AR <dbl>
Arrange rows
arrange(Prem,FTHG)
## # A tibble: 380 × 22
## Date HomeTeam AwayTeam FTHG FTAG FTR HTHG HTAG HTR Referee HS
## <chr> <chr> <chr> <dbl> <dbl> <chr> <dbl> <dbl> <chr> <chr> <dbl>
## 1 14/08/20… Norwich Liverpo… 0 3 A 0 1 A A Marr… 14
## 2 21/08/20… Crystal… Brentfo… 0 0 D 0 0 D M Atki… 7
## 3 22/08/20… Wolves Tottenh… 0 1 A 0 1 A S Attw… 25
## 4 22/08/20… Arsenal Chelsea 0 2 A 0 2 A P Tier… 6
## 5 28/08/20… Brighton Everton 0 2 A 0 1 A J Moss 14
## 6 29/08/20… Wolves Man Uni… 0 1 A 0 0 D M Dean 15
## 7 44509 Brentfo… Brighton 0 1 A 0 0 D G Scott 7
## 8 44509 Leicest… Man City 0 1 A 0 0 D P Tier… 6
## 9 44509 Southam… West Ham 0 0 D 0 0 D D Coote 11
## 10 44509 Watford Wolves 0 2 A 0 0 D P Bank… 6
## # ℹ 370 more rows
## # ℹ 11 more variables: AS <dbl>, HST <dbl>, AST <dbl>, HF <dbl>, AF <dbl>,
## # HC <dbl>, AC <dbl>, HY <dbl>, AY <dbl>, HR <dbl>, AR <dbl>
Select columns
select(Prem, "HomeTeam","AwayTeam",FTHG,FTAG)
## # A tibble: 380 × 4
## HomeTeam AwayTeam FTHG FTAG
## <chr> <chr> <dbl> <dbl>
## 1 Brentford Arsenal 2 0
## 2 Man United Leeds 5 1
## 3 Burnley Brighton 1 2
## 4 Chelsea Crystal Palace 3 0
## 5 Everton Southampton 3 1
## 6 Leicester Wolves 1 0
## 7 Watford Aston Villa 3 2
## 8 Norwich Liverpool 0 3
## 9 Newcastle West Ham 2 4
## 10 Tottenham Man City 1 0
## # ℹ 370 more rows
Add columns
mutate(Prem,
goaldifferential = FTHG - FTAG)
## # A tibble: 380 × 23
## Date HomeTeam AwayTeam FTHG FTAG FTR HTHG HTAG HTR Referee HS
## <chr> <chr> <chr> <dbl> <dbl> <chr> <dbl> <dbl> <chr> <chr> <dbl>
## 1 13/08/20… Brentfo… Arsenal 2 0 H 1 0 H M Oliv… 8
## 2 14/08/20… Man Uni… Leeds 5 1 H 1 0 H P Tier… 16
## 3 14/08/20… Burnley Brighton 1 2 A 1 0 H D Coote 14
## 4 14/08/20… Chelsea Crystal… 3 0 H 2 0 H J Moss 13
## 5 14/08/20… Everton Southam… 3 1 H 0 1 A A Madl… 14
## 6 14/08/20… Leicest… Wolves 1 0 H 1 0 H C Paws… 9
## 7 14/08/20… Watford Aston V… 3 2 H 2 0 H M Dean 13
## 8 14/08/20… Norwich Liverpo… 0 3 A 0 1 A A Marr… 14
## 9 15/08/20… Newcast… West Ham 2 4 A 2 1 H M Atki… 17
## 10 15/08/20… Tottenh… Man City 1 0 H 0 0 D A Tayl… 13
## # ℹ 370 more rows
## # ℹ 12 more variables: AS <dbl>, HST <dbl>, AST <dbl>, HF <dbl>, AF <dbl>,
## # HC <dbl>, AC <dbl>, HY <dbl>, AY <dbl>, HR <dbl>, AR <dbl>,
## # goaldifferential <dbl>
Summarize by groups
Prem %>%
group_by(HomeTeam) %>%
summarise(FTHG= mean(FTHG, na.rm = TRUE))
## # A tibble: 20 × 2
## HomeTeam FTHG
## <chr> <dbl>
## 1 Arsenal 1.84
## 2 Aston Villa 1.53
## 3 Brentford 1.16
## 4 Brighton 1
## 5 Burnley 0.947
## 6 Chelsea 1.95
## 7 Crystal Palace 1.42
## 8 Everton 1.42
## 9 Leeds 1
## 10 Leicester 1.79
## 11 Liverpool 2.58
## 12 Man City 3.05
## 13 Man United 1.68
## 14 Newcastle 1.37
## 15 Norwich 0.632
## 16 Southampton 1.21
## 17 Tottenham 2
## 18 Watford 0.895
## 19 West Ham 1.74
## 20 Wolves 1.05