Alice:“How long is forever”? White Rabbit:“Sometimes, just one second.”

Alice :“Where should I go?” The Cheshire Cat: “That depends on where you want to end up.”

“I’m not strange, weird, off, nor crazy, my reality is just different from yours.”

        Alice through the looking glass - Lewis Caroll

Introduction

In this post, my R package ‘yorkr’, continues to bat in the Twenty20s. This post is a continuation of my earlier post - yorkr pads up for the Twenty20s: Part 1- Analyzing team“s match performance. This post deals with Class 2 functions namely the performances of a team in all T20 matches against a single opposition for e.g all T20 matches of India-Australia, Pakistan-West Indies etc. You can clone/fork the code for my package yorkr from Github at yorkr

This post has also been published at RPubs yorkrT20-Part2 and can also be downloaded as a PDF document from yorkrT20-Part2.pdf

The list of function in Class 2 are

  1. teamBatsmenPartnershiOppnAllMatches()
  2. teamBatsmenPartnershipOppnAllMatchesChart()
  3. teamBatsmenVsBowlersOppnAllMatches()
  4. teamBattingScorecardOppnAllMatches()
  5. teamBowlingPerfOppnAllMatches()
  6. teamBowlersWicketsOppnAllMatches()
  7. teamBowlersVsBatsmenOppnAllMatches()
  8. teamBowlersWicketKindOppnAllMatches()
  9. teamBowlersWicketRunsOppnAllMatches()
  10. plotWinLossBetweenTeams()

1. Install the package from CRAN

library(yorkr)
rm(list=ls())

2. Get data for all T20 matches between 2 teams

We can get all T20 matches between any 2 teams using the function below. The dir parameter should point to the folder which has the T20 RData files of the individual matches. This function creates a data frame of all the T20 matches and also saves the dataframe as RData. The function below gets all matches between India and Australia

setwd("C:/software/cricket-package/york-test/yorkrData/Twenty20/T20-matches")
matches <- getAllMatchesBetweenTeams("Australia","India",dir=".")
dim(matches)
## [1] 2829   25

I have however already saved the Twenty20 matches for all possible combination of opposing countries. The data for these matches for the individual teams/countries can be obtained from Github at in the folder T20-allmatches-between-two-teams. However you will need to utilize these functions for new match files added to Cricsheet.

3. Save data for all matches between all combination of 2 teams

This can be done locally using the function below. You could use this function to combine all Twenty20 matches between any 2 teams into a single dataframe and save it in the current folder. The current implementation expectes that the the RData files of individual matches are in ../data folder. Since I already have converted this I will not be running this again

#saveAllMatchesBetweenTeams()

4. Load data directly for all matches between 2 teams

As in my earlier post I pick all Twenty20 matches between 2 random teams. I load the data directly from the stored RData files. When we load the Rdata file a “matches” object will be created. This object can be stored for the apporpriate teams as below

# Load T20 matches between teams
setwd("C:/software/cricket-package/york-test/yorkrData/Twenty20/T20-allmatches-between-two-teams")
load("India-Australia-allMatches.RData")
aus_ind_matches <- matches
dim(aus_ind_matches)
## [1] 2829   25
load("England-New Zealand-allMatches.RData")
eng_nz_matches <- matches
dim(eng_nz_matches)
## [1] 2760   25
load("Pakistan-South Africa-allMatches.RData")
pak_sa_matches <- matches
dim(pak_sa_matches)
## [1] 2308   25
load("Sri Lanka-West Indies-allMatches.RData")
sl_wi_matches <- matches
dim(sl_wi_matches)
## [1] 1909   25
load("Bangladesh-Ireland-allMatches.RData")
ban_ire_matches <-matches
dim(ban_ire_matches)
## [1] 479  25
load("Scotland-Canada-allMatches.RData")
sco_can_matches <-matches
dim(sco_can_matches)
## [1] 250  25
load("Netherlands-Afghanistan-allMatches.RData")
nl_afg_matches <- matches
dim(nl_afg_matches)
## [1] 927  25

5. Team Batsmen partnership in Twenty20 (all matches with opposition)

This function will create a report of the batting partnerships in the teams. The report can be brief or detailed depending on the parameter ‘report’. The top batsmen in India-Australia clashes are Shane Watson & AJ Finch from Australia and Virat Kohli & Yuvraj Singh of India.

m<- teamBatsmenPartnershiOppnAllMatches(aus_ind_matches,'Australia',report="summary")
m
## Source: local data frame [40 x 2]
## 
##         batsman totalRuns
##          (fctr)     (dbl)
## 1     SR Watson       284
## 2      AJ Finch       249
## 3     DA Warner       204
## 4       MS Wade       125
## 5     DJ Hussey       101
## 6     ML Hayden        79
## 7    RT Ponting        76
## 8     MJ Clarke        65
## 9     A Symonds        63
## 10 AC Gilchrist        59
## ..          ...       ...
m <-teamBatsmenPartnershiOppnAllMatches(aus_ind_matches,'India',report="summary")
m
## Source: local data frame [23 x 2]
## 
##         batsman totalRuns
##          (fctr)     (dbl)
## 1       V Kohli       319
## 2  Yuvraj Singh       262
## 3     RG Sharma       252
## 4      MS Dhoni       213
## 5     G Gambhir       198
## 6      SK Raina       160
## 7      S Dhawan       105
## 8    RV Uthappa        70
## 9     IK Pathan        57
## 10     V Sehwag        41
## ..          ...       ...
m <-teamBatsmenPartnershiOppnAllMatches(aus_ind_matches,'Australia',report="detailed")
m[1:30,]
##      batsman   nonStriker partnershipRuns totalRuns
## 1  SR Watson     AJ Finch              21       284
## 2  SR Watson   GJ Maxwell               3       284
## 3  SR Watson    DA Warner             127       284
## 4  SR Watson     SE Marsh              41       284
## 5  SR Watson      TM Head              63       284
## 6  SR Watson      CA Lynn              23       284
## 7  SR Watson   UT Khawaja               2       284
## 8  SR Watson  CT Bancroft               4       284
## 9   AJ Finch    BJ Haddin              15       249
## 10  AJ Finch NJ Maddinson              21       249
## 11  AJ Finch    SR Watson              25       249
## 12  AJ Finch   GJ Maxwell              12       249
## 13  AJ Finch MC Henriques              21       249
## 14  AJ Finch    DA Warner              44       249
## 15  AJ Finch    DJ Hussey              25       249
## 16  AJ Finch      MS Wade               1       249
## 17  AJ Finch     SE Marsh              66       249
## 18  AJ Finch    SPD Smith              16       249
## 19  AJ Finch      TM Head               0       249
## 20  AJ Finch      CA Lynn               3       249
## 21 DA Warner     AJ Finch              30       204
## 22 DA Warner    SR Watson             110       204
## 23 DA Warner   GJ Maxwell              11       204
## 24 DA Warner    DJ Hussey              22       204
## 25 DA Warner     CL White               6       204
## 26 DA Warner      MS Wade              25       204
## 27   MS Wade     AJ Finch               2       125
## 28   MS Wade  JP Faulkner               6       125
## 29   MS Wade    DA Warner              12       125
## 30   MS Wade    DJ Hussey              54       125
m <-teamBatsmenPartnershiOppnAllMatches(pak_sa_matches,'Pakistan',report="summary")
m
## Source: local data frame [24 x 2]
## 
##            batsman totalRuns
##             (fctr)     (dbl)
## 1       Umar Akmal       255
## 2  Mohammad Hafeez       205
## 3    Shahid Afridi       165
## 4    Ahmed Shehzad        85
## 5     Shoaib Malik        80
## 6    Nasir Jamshed        69
## 7    Misbah-ul-Haq        63
## 8     Kamran Akmal        62
## 9     Abdul Razzaq        62
## 10  Sohaib Maqsood        41
## ..             ...       ...
m <-teamBatsmenPartnershiOppnAllMatches(eng_nz_matches,'England',report="summary")
m
## Source: local data frame [35 x 2]
## 
##           batsman totalRuns
##            (fctr)     (dbl)
## 1       LJ Wright       273
## 2        AD Hales       194
## 3         MJ Lumb       188
## 4      EJG Morgan       152
## 5      JC Buttler       140
## 6    KP Pietersen       112
## 7         OA Shah        91
## 8  PD Collingwood        86
## 9         IR Bell        73
## 10        JE Root        68
## ..            ...       ...
m <-teamBatsmenPartnershiOppnAllMatches(sl_wi_matches,'Sri Lanka',report="summary")
m[1:20,]
## Source: local data frame [20 x 2]
## 
##             batsman totalRuns
##              (fctr)     (dbl)
## 1        TM Dilshan       334
## 2  DPMD Jayawardene       202
## 3     KC Sangakkara       135
## 4     ST Jayasuriya       111
## 5        AD Mathews        98
## 6       MDKJ Perera        78
## 7  DSNFG Jayasuriya        66
## 8   HDRL Thirimanne        48
## 9      LD Chandimal        41
## 10  KMDN Kulasekara        30
## 11        LPC Silva        18
## 12        J Mubarak        15
## 13  TAM Siriwardana        15
## 14    CK Kapugedera         8
## 15       SL Malinga         7
## 16       S Prasanna         6
## 17      BMAJ Mendis         3
## 18      NLTC Perera         3
## 19  SMSM Senanayake         3
## 20     PVD Chameera         3
m <- teamBatsmenPartnershiOppnAllMatches(ban_ire_matches,"Ireland",report="summary")
m
## Source: local data frame [11 x 2]
## 
##            batsman totalRuns
##             (fctr)     (dbl)
## 1        GC Wilson        51
## 2  WTS Porterfield        49
## 3       NJ O'Brien        48
## 4       KJ O'Brien        39
## 5        JF Mooney        18
## 6      MC Sorensen        12
## 7         EC Joyce        11
## 8      DT Johnston         7
## 9      PR Stirling         4
## 10         JP Bray         2
## 11       AR Cusack         1

6. Team batsmen partnership in Twenty20 (all matches with opposition)

This is plotted graphically in the charts below. Kohli & Yuvraj top the list for India.

teamBatsmenPartnershipOppnAllMatchesChart(aus_ind_matches,"India","Australia")

teamBatsmenPartnershipOppnAllMatchesChart(pak_sa_matches,main="South Africa",opposition="Pakistan")

m<- teamBatsmenPartnershipOppnAllMatchesChart(eng_nz_matches,"New Zealand",opposition="England",plot=FALSE)
m[1:30,]
##          batsman    nonStriker runs
## 1  HD Rutherford    MJ Guptill   69
## 2  HD Rutherford   BB McCullum   61
## 3    BB McCullum    MJ Guptill   53
## 4     MJ Guptill HD Rutherford   52
## 5    BB McCullum KS Williamson   51
## 6    BB McCullum HD Rutherford   49
## 7    LRPL Taylor   BB McCullum   49
## 8    BB McCullum   LRPL Taylor   46
## 9     MJ Guptill   BB McCullum   41
## 10     SB Styris   CD McMillan   40
## 11   CD McMillan      JDP Oram   38
## 12  JEC Franklin   LRPL Taylor   33
## 13   LRPL Taylor KS Williamson   32
## 14 KS Williamson   LRPL Taylor   32
## 15     SB Styris   LRPL Taylor   31
## 16   LRPL Taylor     SB Styris   30
## 17   BB McCullum      JD Ryder   29
## 18      JDP Oram      JS Patel   28
## 19      JD Ryder   BB McCullum   27
## 20   BB McCullum  JEC Franklin   26
## 21      DR Flynn     SB Styris   22
## 22    TWM Latham   LRPL Taylor   22
## 23 KS Williamson    MJ Santner   21
## 24  JEC Franklin   NL McCullum   21
## 25       C Munro    MJ Guptill   21
## 26   LRPL Taylor        JM How   19
## 27   LRPL Taylor    MJ Guptill   19
## 28   CD McMillan     SB Styris   19
## 29    MJ Guptill  JEC Franklin   19
## 30   BB McCullum     SB Styris   18
teamBatsmenPartnershipOppnAllMatchesChart(sl_wi_matches,"Sri Lanka","West Indies")

teamBatsmenPartnershipOppnAllMatchesChart(ban_ire_matches,"Bangladesh","Ireland")

7. Team batsmen versus bowler in Twenty20 (all matches with opposition)

The plots below provide information on how each of the top batsmen fared against the opposition bowlers

teamBatsmenVsBowlersOppnAllMatches(aus_ind_matches,"India","Australia")

teamBatsmenVsBowlersOppnAllMatches(pak_sa_matches,"South Africa","Pakistan",top=3)