yorkr is generic!

The features and functionality in my yorkr package is now complete. My R package yorkr, is totally generic, which means that the R package  can be used for all ODI, T20 matches. Hence yorkr can be used for professional or amateur ODI and T20 matches. The R package can be used for both men and women ODI, T20 international or domestic matches. The main requirement is, that the match data  be created as a Yaml file in the format Cricsheet (Required yaml format for the match data).

If you are passionate about cricket, and love analyzing cricket performances, then check out my 2 racy books on cricket! In my books, I perform detailed yet compact analysis of performances of both batsmen, bowlers besides evaluating team & match performances in Tests , ODIs, T20s & IPL. You can buy my books on cricket from Amazon at $12.99 for the paperback and $4.99/$6.99 respectively for the kindle versions. The books can be accessed at Cricket analytics with cricketr  and Beaten by sheer pace-Cricket analytics with yorkr  A must read for any cricket lover! Check it out!!

1

$4.99/Rs 320 and $6.99/Rs448 respectively

 

I have successfully used my R functions for the Indian Premier League (IPL) matches with changes only to the convertAllYamlFiles2RDataFramesXX (please see posts below)

The convertAllYamlFiles2RDataframes &convertAllYamlFiles2RDataFramesT20 will have to be customized for the names of the teams playing in the domestic professional or amateur matches. All other classes of functions namely Class1, Class2, Class 3 and Class 4 as discussed in my post Introducing cricket package yorkr-Part 1: Beaten by sheer pace can be used as is without any changes.

There are numerous professional & amateur T20 matches that are played around the world. Here are a list of domestic T20 tournaments that are played around the world (from Wikipedia). The yorkr package can be used for any of these matches once the match data is saved as yaml as mentioned above.

So do go ahead and have fun, analyzing cricket performances with yorkr!

Please take a look at my posts on how to use yorkr for ODI, Twenty20 matches.

  1. Introducing cricket package yorkr:Part 1- Beaten by sheer pace!
    2. Introducing cricket package yorkr:Part 2- Trapped leg before wicket!
    3.  Introducing cricket package yorkr:Part 3- foxed by flight!
    4. Introducing cricket package yorkr:Part 4-In the block hole!
    5. yorkr pads up for the Twenty20s: Part 1- Analyzing team”s match performance
    6. yorkr pads up for the Twenty20s: Part 2-Head to head confrontation between teams
    7. yorkr pads up for the Twenty20s:Part 3:Overall team performance against all oppositions!
    8. yorkr pads up for Twenty20s:Part 4- Individual batting and bowling performances!
    9. yorkr crashes the IPL party ! – Part 1
    10. yorkr crashes the IPL party! – Part 2
    11. yorkr crashes the IPL party! – Part 3
    12. yorkr crashes the IPL party! – Part 4
    13. yorkr ranks IPL batsmen and bowlers
    14. yorkr ranks T20 batsmen and bowlers
    15. yorkr ranks ODI batsmen and bowlers

yorkr pads up for the Twenty20s: Part 1- Analyzing team”s match performance

There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.

      C.A.R. Hoare, The 1980 ACM Turing Award LectureOne of my most productive days was throwing away 1000 lines of code.
      Ken Thompson

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

      Brian W. Kernighan and P. J. Plauger in The Elements of Programming Style.
      

“If debugging is the process of removing software bugs, then programming must be the process of putting them in.”

      Edsger Dijkstra

Introduction

In this post I have added functions to my R package ‘yorkr’ that will allow for analysis of Twenty20 matches. yorkr is already available in CRAN and the Twenty20 functionality will be available with yorkr_0.0.4. This package is based on data from Cricsheet. I have now added functionality to perform analysis of T20 matches in addition the existing functionality for analysing ODI matches

The yorkr package provides functions to convert the yaml files to more easily R consumable entities, namely dataframes. In fact all ODI & T20 matches have already been converted and are available for use at yorkrData. However you will have to convert any new matches added to Cricsheet. Also note that there is a file called ’convertedFiles” which will give the details of the original match file and its corresponding converted file.

If you are passionate about cricket, and love analyzing cricket performances, then check out my 2 racy books on cricket! In my books, I perform detailed yet compact analysis of performances of both batsmen, bowlers besides evaluating team & match performances in Tests , ODIs, T20s & IPL. You can buy my books on cricket from Amazon at $12.99 for the paperback and $4.99/$6.99 respectively for the kindle versions. The books can be accessed at Cricket analytics with cricketr  and Beaten by sheer pace-Cricket analytics with yorkr  A must read for any cricket lover! Check it out!!

1

 

This post can be viewed at RPubs at yorkrT20-Part1 or can also be downloaded as a PDF document yorkrT20-1.pdf

Checkout my interactive Shiny apps GooglyPlus (plots & tables) and Googly (only plots) which can be used to analyze IPL players, teams and matches.

Note: To do similar analysis you can use my yorkrT20templates. See my post Analysis of International T20 matches with yorkr templates

Important note 1: Do check out all the posts on the python avatar of yorkr, namely ‘yorkpy’ in my post ‘Pitching yorkpy … short of good length to IPL – Part 1

2. Install the package from CRAN

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

2a. New functionality for Twenty20

I had to create 2 new functions had to be created for converting Twenty20 yaml files to RData. They are

  1. convertYaml2RDataframeT20
  2. convertAllYaml2RDataframesT20

Note: Most of the existing functions created for ODI matches, also work with the converted T20 RData files, as can be seen below.

3. Convert and save T20 yaml file to dataframe

This function will convert a T20 yaml file in the format as specified in Cricsheet to dataframe. This will be saved as as RData file in the target directory. The name of the file wil have the following format team1-team2-date.RData. An example of how a yaml file can be converted to a dataframe and saved is shown below.

#Available in yorkr_0.0.4
convertYaml2RDataframeT20("211028.yaml",".",".") 
## [1] "./211028.yaml"
## [1] "first loop"
## [1] "second loop"

4. Convert and save all T20 yaml files to dataframes

This function will convert all T20 yaml files from a source directory to dataframes, and save it in the target directory, with the names as mentioned above. Since I have already done this, I will not be executing this again. You can download the zip of all the converted RData files from Github at T20-matches

#Available from yorkr_0.0.4
#convertAllYaml2RDataframesT20("./t20s",targetDirMen=".",targetDirWomen=".")

5. yorkrData – A Github repositiory

Cricsheet had a total of 458 Twenty20 matches. Out of which 5 files seemed to have problem. The remaining 453 T20 matches have been converted to RData.

All the converted RData files can be accessed from my Github link yorkrData under the folder T20-matches

You can download the the zip of the files and use it directly in the functions as follows

6. Load the match data as dataframes

For this post I will be using the Twenty20 match data from 5 random matches between 10 different opposing teams/countries. For this I will directly use the converted RData files rather than getting the data through the getMatchDetails() as shown below

With the RData we can load the data in 2 ways

A. With getMatchDetails()

  1. With getMatchDetails() using the 2 teams and the date on which the match occured
afg_ire <- getMatchDetails("Afghanistan","Ireland","2010-02-09",dir="../../data")
dim(afg_ire)
## [1] 245  25

or

B.Directly load RData into your code.

The match details will be loaded into a dataframe called ’overs’ which you can assign to a suitable name as below

The randomly selected matches are

  • Australia vs India – 2007-09-22
  • England vs New Zealand – 2012-09-29
  • Pakistan vs South Africa – 2010-10-26
  • Sri Lanka vs West Indioes -2012-10-07
  • Bangladesh vs Zimbabwe -2016-01-15
load("../../data/Australia-India-2007-09-22.RData")
aus_ind <- overs
load("../../data/England-New Zealand-2012-09-29.RData")
eng_nz <- overs
load("../../data/Pakistan-South Africa-2010-10-26.RData")
pak_sa <- overs
load("../../data/Sri Lanka-West Indies-2012-10-07.RData")
sl_wi<- overs
load("../../data/Bangladesh-Zimbabwe-2016-01-15.RData")
ban_zim <- overs

7. Team batting scorecard

Compute and display the batting scorecard of the teams in the T20 match. The top batsmen in are Yuvraj Singh(Ind), ML Hayden(Aus), JP Duminy(SA) and Jayawardene(SL)

teamBattingScorecardMatch(aus_ind,'India')
## Total= 181
## Source: local data frame [7 x 5]
## 
##        batsman ballsPlayed fours sixes  runs
##         (fctr)       (int) (dbl) (dbl) (dbl)
## 1    G Gambhir          25     4     0    24
## 2     V Sehwag          12     1     0     9
## 3   RV Uthappa          27     1     3    34
## 4 Yuvraj Singh          30     5     5    70
## 5     MS Dhoni          18     4     1    36
## 6    RG Sharma           5     0     1     8
## 7    IK Pathan          NA     0     0     0
teamBattingScorecardMatch(aus_ind,'Australia')
## Total= 165
## Source: local data frame [9 x 5]
## 
##        batsman ballsPlayed fours sixes  runs
##         (fctr)       (int) (dbl) (dbl) (dbl)
## 1 AC Gilchrist          13     2     2    22
## 2    ML Hayden          44     4     4    62
## 3     BJ Hodge          10     0     1    11
## 4    A Symonds          26     3     2    43
## 5   MEK Hussey          12     0     1    13
## 6    MJ Clarke           3     0     0     3
## 7    BJ Haddin           7     0     0     5
## 8        B Lee           2     0     0     2
## 9   MG Johnson           1     1     0     4
teamBattingScorecardMatch(pak_sa,'South Africa')
## Total= 115
## Source: local data frame [6 x 5]
## 
##          batsman ballsPlayed fours sixes  runs
##           (fctr)       (int) (dbl) (dbl) (dbl)
## 1       GC Smith          12     3     0    13
## 2      LE Bosman           4     0     0     2
## 3 AB de Villiers           3     0     0     0
## 4      JP Duminy          45     5     0    41
## 5      CA Ingram          38     4     2    46
## 6      DA Miller           5     3     0    13
teamBattingScorecardMatch(sl_wi,'Sri Lanka')
## Total= 98
## Source: local data frame [10 x 5]
## 
##             batsman ballsPlayed fours sixes  runs
##              (fctr)       (int) (dbl) (dbl) (dbl)
## 1  DPMD Jayawardene          36     2     0    33
## 2        TM Dilshan           2     0     0     0
## 3     KC Sangakkara          26     2     0    22
## 4        AD Mathews           5     0     0     1
## 5       BMAJ Mendis           3     0     0     3
## 6       NLTC Perera           5     0     0     3
## 7   HDRL Thirimanne           7     0     0     4
## 8   KMDN Kulasekara          12     3     1    26
## 9        SL Malinga          12     0     0     5
## 10       BAW Mendis           2     0     0     1

8. Plot the team batting partnerships

The functions below plot the team batting partnetship in the T20 match Note: Many of the plots include an additional parameters plot which is either TRUE or FALSE. The default value is plot=TRUE. When plot=TRUE the plot will be displayed. When plot=FALSE the data frame will be returned to the user. The user can use this to create an interactive chary using one of th epackages like rcharts, ggvis,googleVis or plotly.

teamBatsmenPartnershipMatch(pak_sa,"Pakistan","South Africa")

batsmenPartnership-1

teamBatsmenPartnershipMatch(eng_nz,"New Zealand","England",plot=TRUE)

batsmenPartnership-2

teamBatsmenPartnershipMatch(ban_zim,"Bangladesh","Zimbabwe",plot=FALSE)
##            batsman      nonStriker runs
## 1      Tamim Iqbal   Soumya Sarkar   19
## 2      Tamim Iqbal   Sabbir Rahman   10
## 3    Soumya Sarkar     Tamim Iqbal    7
## 4    Sabbir Rahman     Tamim Iqbal   15
## 5    Sabbir Rahman   Shuvagata Hom   10
## 6    Sabbir Rahman Mushfiqur Rahim   21
## 7    Shuvagata Hom   Sabbir Rahman    6
## 8  Mushfiqur Rahim   Sabbir Rahman   23
## 9  Mushfiqur Rahim Shakib Al Hasan    3
## 10 Shakib Al Hasan Mushfiqur Rahim    4
## 11 Shakib Al Hasan     Mahmudullah    5
## 12 Shakib Al Hasan     Nurul Hasan   11
## 13     Mahmudullah Shakib Al Hasan    7
## 14     Nurul Hasan Shakib Al Hasan    7
teamBatsmenPartnershipMatch(aus_ind,"India","Australia",plot=TRUE)

batsmenPartnership-3

9. Batsmen vs Bowler

The function below computes and plots the performances of the batsmen vs the bowlers. As before the plot parameter can be set to TRUE or FALSE. By default it is plot=TRUE

teamBatsmenVsBowlersMatch(pak_sa,'Pakistan',"South Africa",plot=TRUE)

batsmenVsBowler-1

teamBatsmenVsBowlersMatch(aus_ind,'Australia',"India",plot=TRUE)

batsmenVsBowler-2

teamBatsmenVsBowlersMatch(ban_zim,'Zimbabwe',"Bangladesh",plot=TRUE)

batsmenVsBowler-3

m <- teamBatsmenVsBowlersMatch(sl_wi,'West Indies',"Sri Lanka",plot=FALSE)
m
## Source: local data frame [25 x 3]
## Groups: batsman [?]
## 
##       batsman          bowler runsConceded
##        (fctr)          (fctr)        (dbl)
## 1   J Charles      AD Mathews            0
## 2  MN Samuels      AD Mathews            8
## 3  MN Samuels KMDN Kulasekara            5
## 4  MN Samuels      SL Malinga           39
## 5  MN Samuels      BAW Mendis            7
## 6  MN Samuels     A Dananjaya            4
## 7  MN Samuels     BMAJ Mendis           15
## 8    CH Gayle      AD Mathews            0
## 9    CH Gayle KMDN Kulasekara            1
## 10   CH Gayle      SL Malinga            2
## ..        ...             ...          ...

10. Bowling Scorecard

This function provides the bowling performance, the number of overs bowled, maidens, runs conceded and wickets taken for each match

teamBowlingScorecardMatch(eng_nz,'England')
## Source: local data frame [5 x 5]
## 
##       bowler overs maidens  runs wickets
##       (fctr) (int)   (int) (dbl)   (dbl)
## 1  DR Briggs     4       0    36       1
## 2    ST Finn     4       0    16       3
## 3 TT Bresnan     4       0    29       1
## 4   GP Swann     4       0    20       1
## 5  SCJ Broad     4       0    37       0
teamBowlingScorecardMatch(eng_nz,'New Zealand')
## Source: local data frame [7 x 5]
## 
##          bowler overs maidens  runs wickets
##          (fctr) (int)   (int) (dbl)   (dbl)
## 1      KD Mills     4       0    23       1
## 2    TG Southee     2       0    32       0
## 3    DL Vettori     4       0    20       1
## 4   NL McCullum     4       0    22       1
## 5      RJ Nicol     3       0    29       0
## 6  JEC Franklin     1       0    12       0
## 7 DAJ Bracewell     1       0     8       1
teamBowlingScorecardMatch(aus_ind,'Australia')
## Source: local data frame [6 x 5]
## 
##       bowler overs maidens  runs wickets
##       (fctr) (int)   (int) (dbl)   (dbl)
## 1      B Lee     4       0    25       0
## 2 NW Bracken     4       0    38       0
## 3   SR Clark     4       0    38       0
## 4 MG Johnson     4       0    31       4
## 5  A Symonds     3       0    37       0
## 6  MJ Clarke     1       0    13       1

11. Wicket Kind

The plots below provide the bowling kind of wicket taken by the bowler (caught, bowled, lbw etc.)

teamBowlingWicketKindMatch(aus_ind,"India","Australia")

bowlingWicketKind-1

teamBowlingWicketKindMatch(aus_ind,"Australia","India")

bowlingWicketKind-2

teamBowlingWicketKindMatch(pak_sa,"South Africa","Pakistan")

bowlingWicketKind-3

m <-teamBowlingWicketKindMatch(sl_wi,"Sri Lanka","West Indies",plot=FALSE)
m
##            bowler wicketKind wicketPlayerOut runs
## 1      AD Mathews     caught       J Charles   11
## 2      BAW Mendis        lbw        CH Gayle   12
## 3      BAW Mendis        lbw        DJ Bravo   12
## 4      BAW Mendis     caught      KA Pollard   12
## 5      BAW Mendis        lbw      AD Russell   12
## 6     A Dananjaya     caught      MN Samuels   16
## 7 KMDN Kulasekara   noWicket        noWicket   22
## 8      SL Malinga   noWicket        noWicket   54
## 9     BMAJ Mendis   noWicket        noWicket   20

12. Wicket vs Runs conceded

The plots below provide the wickets taken and the runs conceded by the bowler in the match

teamBowlingWicketRunsMatch(pak_sa,"Pakistan","South Africa")

wicketRuns-1

teamBowlingWicketRunsMatch(aus_ind,"Australia","India")

wicketRuns-2

m <-teamBowlingWicketRunsMatch(sl_wi,"West Indies","Sri Lanka",plot=FALSE)
m
## Source: local data frame [6 x 5]
## 
##       bowler overs maidens  runs wickets
##       (fctr) (int)   (int) (dbl)   (chr)
## 1   S Badree     4       0    24       1
## 2  R Rampaul     3       0    31       1
## 3 MN Samuels     4       0    15       2
## 4   CH Gayle     2       0    14       0
## 5  SP Narine     4       1     9       4
## 6  DJG Sammy     2       0     6       2

13. Wickets taken by bowler

The plots provide the wickets taken by the bowler

m <-teamBowlingWicketMatch(eng_nz,'England',"New Zealand",plot=FALSE)
m
##       bowler wicketKind wicketPlayerOut runs
## 1    ST Finn        lbw      MJ Guptill   16
## 2    ST Finn     caught     BB McCullum   16
## 3   GP Swann     caught        RJ Nicol   20
## 4  DR Briggs     caught   KS Williamson   36
## 5    ST Finn     caught     LRPL Taylor   16
## 6 TT Bresnan    run out    JEC Franklin   29
## 7  SCJ Broad   noWicket        noWicket   37
teamBowlingWicketMatch(sl_wi,"Sri Lanka","West Indies")

bowlingWickets-1

teamBowlingWicketMatch(eng_nz,"New Zealand","England")

bowlingWickets-2

14. Bowler Vs Batsmen

The functions compute and display how the different bowlers of the country performed against the batting opposition.

teamBowlersVsBatsmenMatch(ban_zim,"Bangladesh","Zimbabwe")

bowlerVsBatsmen-1

teamBowlersVsBatsmenMatch(aus_ind,"India","Australia")

bowlerVsBatsmen-2

teamBowlersVsBatsmenMatch(eng_nz,"England","New Zealand")

bowlerVsBatsmen-3

m <- teamBowlersVsBatsmenMatch(pak_sa,"Pakistan","South Africa",plot=FALSE)
m
## Source: local data frame [19 x 3]
## Groups: bowler [?]
## 
##             bowler        batsman runsConceded
##             (fctr)         (fctr)        (dbl)
## 1    Shoaib Akhtar       GC Smith            5
## 2    Shoaib Akhtar      LE Bosman            1
## 3    Shoaib Akhtar AB de Villiers            0
## 4    Shoaib Akhtar      JP Duminy            8
## 5    Shoaib Akhtar      CA Ingram           11
## 6    Shoaib Akhtar      DA Miller            4
## 7     Abdul Razzaq       GC Smith            8
## 8     Abdul Razzaq      LE Bosman            1
## 9     Abdul Razzaq      CA Ingram            1
## 10    Abdul Razzaq      DA Miller            9
## 11 Mohammad Hafeez       GC Smith            0
## 12 Mohammad Hafeez      JP Duminy            7
## 13 Mohammad Hafeez      CA Ingram            3
## 14        Umar Gul      JP Duminy            6
## 15        Umar Gul      CA Ingram           11
## 16     Saeed Ajmal      JP Duminy           10
## 17     Saeed Ajmal      CA Ingram            7
## 18   Shahid Afridi      JP Duminy           10
## 19   Shahid Afridi      CA Ingram           13

15. Match worm graph

The plots below provide the match worm graph for the Twenty 20 matches

matchWormGraph(aus_ind,'Australia',"India")

matchWorm-1

matchWormGraph(sl_wi,'Sri Lanka',"West Indies")

matchWorm-2

Conclusion

This post included all functions between 2 opposing countries from the package yorkr for Twenty20 matches.As mentioned above the yaml match files have been already converted to dataframes and are available for download from Github. Go ahead and give it a try

To be continued. Watch this space!

Important note: Do check out my other posts using yorkr at yorkr-posts

 

You may also like

  1. Introducing cricketr! : An R package to analyze performances of cricketers
  2. Cricket analytics with cricketr
  3. Introducing cricket package yorkr-Part1:Beaten by sheer pace!.
  4. What’s up Watson? Using IBM Watson’s QAAPI with Bluemix, NodeExpress
  5. Introducing cricket package yorkr: Part 3-Foxed by flight!
  6. Natural language processing: What would Shakespeare say?
  7. Experiment with deblurring using OpenCV
  8. Unravelling the mysteries of life
  9. Presentation on “Intelligent Networks, CAMEL protocol, services & applications”

The making of cricket package yorkr – Part 1

Introduction

Here is a sneak preview of my latest package cricket package yorkr in R. My earlier package ‘cricketr’ (see Introducing cricketr: An R package for analyzing performances of cricketers) was based on data from ESPN Cricinfo Statsguru. My current package ‘yorkr’ is based on data from Cricsheet. The data for Test, ODI, Twenty20 matches in Cricheet are formatted as yaml files.

While the data available from ESPN Cricinfo Statsguru is a summary of the player’s performances, Cricsheet data is more detailed and granular. Cricsheet gives a ball-by-ball detail for each match as can be seen from the above website. Hence the type of analyses possible can be much more detailed and richer. Some cool functions in this package, include charts for batsman partnerships, performance of batsman against bowlers and how bowlers fared against batsman for a single ODI match or for all ODI matches between 2 opposing sides (for e.g Australia-India or West Indies-Sri Lanka)

This current post includes my first stab at analysing ODI data from Cricsheet. To do this I had to parse the Yaml files and flatten them out as data frames. That was a fairly involved task and I think I now have done it. I then perform analyses on these flattened 1000’s of data frames. This post contains my initial analyses of the ODI data from Cricsheet.

Since the package ‘yorkr’ is still work in progress. I will be adding more functions, refining existing functions and crossing t’s and dotting the i’s. I hope to have the yorkr package wrapped up in about 6-10 weeks time. The package and code should be available after that. Please ‘hold your horses’ till this time.

If you are passionate about cricket, and love analyzing cricket performances, then check out my 2 racy books on cricket! In my books, I perform detailed yet compact analysis of performances of both batsmen, bowlers besides evaluating team & match performances in Tests , ODIs, T20s & IPL. You can buy my books on cricket from Amazon at $12.99 for the paperback and $4.99/$6.99 respectively for the kindle versions. The books can be accessed at Cricket analytics with cricketr  and Beaten by sheer pace-Cricket analytics with yorkr  A must read for any cricket lover! Check it out!!

1

 

This report is also available at Rpubs at yorkr1 york1. The report can also be downloaded as a PDF document at yorkr-1.pdf

 

Checkout my interactive Shiny apps GooglyPlus (plots & tables) and Googly (only plots) which can be used to analyze IPL players, teams and matches.

Important note: Do check out all the posts on the python avatar of yorkr, namely ‘yorkpy’ in my post ‘Pitching yorkpy … short of good length to IPL – Part 1

The current set of functions developed fall into 4 main categories

  • batsmen performance in match
  • bowlers performance in match
  • batsmen performance against opposition
  • bowlers performance against opposition

In the first part of the post I have taken an single Australia-India ODI match on 24 Feb 2008 at Sydney. (For details on this match look up Australia – India, Sydney)

The second part of the past looks at all ODI matches between Australia-India (there are 40 ODI matches between India and Australia)

While this post analyses 1 ODI match and all matches between 2 opposing sides (Australia vs India), the functions developed in yorkr(Part 1) can be used for any of 1000+ ODI matches and any combination of opposing countries!!!

So without much ado let me dive into the functions created

library(dplyr)
library(ggplot2)
library(yorkr)

Get the match details (Aus-Ind,24 Feb 2008,Sydney)

match <- getMatchDetails()

Team batting performances of the opposing teams

In this post I pick a ODI match played between India and Australia on 24 Feb 2008 at Sydney.

1. Team batting details (ODI Match)

This function gives the overall scores of the team for which the function is invoked

Team batting details (ODI Match)
This function gives the overall scores of the team for which the function is invoked

teamBattingDetailsMatch(match,"India")
## Total= 272
## Source: local data frame [11 x 5]
## 
##            batsman ballsPlayed fours sixes  runs
##             (fctr)       (int) (dbl) (dbl) (dbl)
## 1         V Sehwag          18     3     0    17
## 2     SR Tendulkar           3     0     0     2
## 3        G Gambhir         118     9     1   113
## 4        RG Sharma           3     0     0     1
## 5     Yuvraj Singh           3     1     0     5
## 6         MS Dhoni          64     4     0    36
## 7       RV Uthappa          40     4     1    51
## 8        IK Pathan          20     2     0    22
## 9  Harbhajan Singh          11     3     0    20
## 10     S Sreesanth           4     0     0     3
## 11        I Sharma           3     0     0     2
teamBattingDetailsMatch(match,"Australia")
## Total= 303
## Source: local data frame [7 x 5]
## 
##        batsman ballsPlayed fours sixes  runs
##         (fctr)       (int) (dbl) (dbl) (dbl)
## 1 AC Gilchrist           7     3     0    16
## 2    ML Hayden          61     5     1    54
## 3   RT Ponting         132     7     1   124
## 4    MJ Clarke          38     0     0    31
## 5    A Symonds          48     6     2    59
## 6   MEK Hussey          10     1     0    15
## 7     JR Hopes           3     0     0     4

2. Batsmen partnership (ODI Match)

The plot below shows the partnerships between batsman. Gautham Gambhir scored the highest followed by Uthappa. Gambhir had a good partnership with Sehway, Dhoni and Uthappa. On the Australian side Ponting had a good partnership with Hayden,Clarke and Symonds.

batsmenPartnershipMatch(match,"India")

partnershipmatch-1

batsmenPartnershipMatch(match,"Australia")

partnershipmatch-2

3. Batsmen vs Bowlers (ODI Match)

This chart shows how each batsman fared against the bowlers. Gambhir scored maximum from Hogg and Clarke. Ponting scores maximum from Pathan, Ishant Sharma, Sreesanth.

batsmenVsBowlersMatch(match,"India")

batsmenbowler-1

batsmenVsBowlersMatch(match,"Australia")

batsmenbowler-2

4. Team bowling details (ODI Match)

The table gives bowling details of each team

teamBowlingDetailsMatch(match,"India")
## Source: local data frame [6 x 5]
## 
##       bowler overs maidens  runs wickets
##       (fctr) (int)   (int) (dbl)   (dbl)
## 1      B Lee    10       2    58       5
## 2 NW Bracken    10       0    53       1
## 3   SR Clark    10       0    55       2
## 4   JR Hopes     6       0    27       1
## 5    GB Hogg     9       0    62       1
## 6  MJ Clarke     5       0    33       0
teamBowlingDetailsMatch(match,"Australia")
## Source: local data frame [6 x 5]
## 
##            bowler overs maidens  runs wickets
##            (fctr) (int)   (int) (dbl)   (dbl)
## 1     S Sreesanth     8       0    58       2
## 2        I Sharma    10       0    65       1
## 3       IK Pathan     9       0    73       0
## 4 Harbhajan Singh     9       0    50       2
## 5        V Sehwag     6       0    28       2
## 6    Yuvraj Singh     8       0    38       0

5. Wicket kind (ODI Match)

This chart gives the wicket kind or the type of wicket for the bowler vs the runs scored

teamBowlingWicketKindMatch(match,"India")

wicketKindmatch-1

teamBowlingWicketKindMatch(match,"Australia")

wicketKindmatch-2

6. Wickets Runs (ODI Match)l

This plot gives the number of wickets taken and the runs conceded by the bowler

teamBowlingWicketRunsMatch(match,"India")

wicketRunsMatch-1

teamBowlingWicketRunsMatch(match,"Australia")

wicketRunsMatch-2

7. Wicket (batsman) and total runs scored (ODI Match)

This plot gives the details of the wickets taken and the runs conceded. Brett Lee has the performance with 5 scalps. On the Indian side Sreesanth, Harbhajan and Sehwag have 2 wickets apiece. Sreesanth is the most expensive,

teamBowlingWicketMatch(match,"India")

wicketMatch-1

teamBowlingWicketMatch(match,"Australia")

wicketMatch-2

8. Bowler vs Batsman (ODI Match)

This plot below shows which of the batsman was most brutal against the bowler or who scored the most against the bowler. Ponting scores most against Pathan.

bowlersVsBatsmanMatch(match,"India")


batsmanMatch,-1

bowlersVsBatsmanMatch(match,"Australia")


batsmanMatch-2

9.

Worm graph (ODI Match) This chart gives the match worm of runs scored against the number deliveries.

matchWormGraph(match,team1="Australia",team2="India")

worm-1

The following charts show the performances of the batsmen and against the opposition. In this case I have chosen India and Australia. Hence the plots below show the best performers(batsmen and bowlers) of either team against their adversary. The below analyses are based on all ODI confrontations between Australia and India. There are a total of 40 head-on confrontations between Aus-India.

allMatches <- getOppositionDetails()

10.Batsman partnership against opposition (all ODI matches)

The report below gives the batsman who has had the best partnetship in Australia-India matches. On the Indian side the top 3 are Mahendra Singh Dhoni, Rohit Sharma followed by Tendulkar. Ponting, Hussey and Bailey are the top 3 for the Autralians. As far as ODI is concerned Dhoni towers over all others. Of course similar analyses can be done between India-Pakistan, India-South Africa etc. But at least against the Australians we need to have Dhoni and Rohit Sharma I think The report below gives a summary of the partnership runs

report <- batsmanPartnershipOppn(allMatches,"India",report="summary")
report
## Source: local data frame [44 x 2]
## 
##         batsman partnershipRuns
##          (fctr)           (dbl)
## 1      MS Dhoni            1156
## 2     RG Sharma             914
## 3  SR Tendulkar             910
## 4       V Kohli             902
## 5     G Gambhir             532
## 6  Yuvraj Singh             524
## 7      SK Raina             509
## 8      S Dhawan             471
## 9      V Sehwag             287
## 10   RV Uthappa             279
## ..          ...             ...
report <- batsmanPartnershipOppn(allMatches,"Australia",report="summary")
report
## Source: local data frame [48 x 2]
## 
##       batsman partnershipRuns
##        (fctr)           (dbl)
## 1  RT Ponting             876
## 2  MEK Hussey             753
## 3   GJ Bailey             610
## 4   SR Watson             609
## 5   MJ Clarke             607
## 6   ML Hayden             573
## 7   A Symonds             536
## 8    AJ Finch             525
## 9   SPD Smith             467
## 10  DA Warner             391
## ..        ...             ...

The report below gives a detailed breakup of the partnership runs

report <- batsmanPartnershipOppn(allMatches,"India",report="detailed")
report[1:40,]
##         batsman      nonStriker runs partnershipRuns
## 1      MS Dhoni    SR Tendulkar   71            1156
## 2      MS Dhoni        R Dravid   27            1156
## 3      MS Dhoni    Yuvraj Singh  128            1156
## 4      MS Dhoni        SK Raina  187            1156
## 5      MS Dhoni          M Kaif    6            1156
## 6      MS Dhoni        D Mongia   23            1156
## 7      MS Dhoni Harbhajan Singh   16            1156
## 8      MS Dhoni       IK Pathan   42            1156
## 9      MS Dhoni       G Gambhir  117            1156
## 10     MS Dhoni       RG Sharma   56            1156
## 11     MS Dhoni      RV Uthappa   51            1156
## 12     MS Dhoni     S Sreesanth   19            1156
## 13     MS Dhoni        I Sharma    4            1156
## 14     MS Dhoni         P Kumar    1            1156
## 15     MS Dhoni         V Kohli   78            1156
## 16     MS Dhoni       RA Jadeja  103            1156
## 17     MS Dhoni        R Ashwin   78            1156
## 18     MS Dhoni        R Sharma    2            1156
## 19     MS Dhoni   R Vinay Kumar   30            1156
## 20     MS Dhoni          Z Khan    6            1156
## 21     MS Dhoni       AM Rahane   47            1156
## 22     MS Dhoni       MK Pandey   34            1156
## 23     MS Dhoni Gurkeerat Singh    1            1156
## 24     MS Dhoni         B Kumar   26            1156
## 25     MS Dhoni        RR Powar    3            1156
## 26    RG Sharma    SR Tendulkar   66             914
## 27    RG Sharma    Yuvraj Singh    5             914
## 28    RG Sharma        SK Raina   69             914
## 29    RG Sharma        MS Dhoni   90             914
## 30    RG Sharma               4    0             914
## 31    RG Sharma       G Gambhir   35             914
## 32    RG Sharma         V Kohli  248             914
## 33    RG Sharma       RA Jadeja   13             914
## 34    RG Sharma        R Ashwin   11             914
## 35    RG Sharma        S Dhawan  247             914
## 36    RG Sharma       AM Rahane   77             914
## 37    RG Sharma       MK Pandey   53             914
## 38 SR Tendulkar        R Dravid   12             910
## 39 SR Tendulkar        V Sehwag  111             910
## 40 SR Tendulkar    Yuvraj Singh  173             910
report <- batsmanPartnershipOppn(allMatches,"Australia",report="detailed")
report[1:40,]
##       batsman   nonStriker runs partnershipRuns
## 1  RT Ponting    SR Watson  140             876
## 2  RT Ponting    DR Martyn   35             876
## 3  RT Ponting    MJ Clarke   63             876
## 4  RT Ponting    BJ Haddin   33             876
## 5  RT Ponting    ML Hayden  117             876
## 6  RT Ponting    A Symonds   41             876
## 7  RT Ponting   MEK Hussey   74             876
## 8  RT Ponting AC Gilchrist  113             876
## 9  RT Ponting     TD Paine   68             876
## 10 RT Ponting     CL White   84             876
## 11 RT Ponting    DA Warner    6             876
## 12 RT Ponting      MS Wade    9             876
## 13 RT Ponting    DJ Hussey   20             876
## 14 RT Ponting     SE Marsh   45             876
## 15 RT Ponting     BJ Hodge   28             876
## 16 MEK Hussey   RT Ponting   85             753
## 17 MEK Hussey    MJ Clarke   74             753
## 18 MEK Hussey    BJ Haddin   24             753
## 19 MEK Hussey      GB Hogg   19             753
## 20 MEK Hussey   MG Johnson   43             753
## 21 MEK Hussey     SR Clark    4             753
## 22 MEK Hussey    ML Hayden    5             753
## 23 MEK Hussey    A Symonds    5             753
## 24 MEK Hussey        B Lee   39             753
## 25 MEK Hussey   NW Bracken    3             753
## 26 MEK Hussey     JR Hopes   83             753
## 27 MEK Hussey     CL White  185             753
## 28 MEK Hussey    DA Warner   10             753
## 29 MEK Hussey      MS Wade   35             753
## 30 MEK Hussey    DJ Hussey   10             753
## 31 MEK Hussey   PJ Forrest   59             753
## 32 MEK Hussey     AC Voges   59             753
## 33 MEK Hussey MC Henriques   11             753
## 34  GJ Bailey    SR Watson   79             610
## 35  GJ Bailey    BJ Haddin    7             610
## 36  GJ Bailey            4    0             610
## 37  GJ Bailey    DA Warner    6             610
## 38  GJ Bailey     AJ Finch   22             610
## 39  GJ Bailey    SPD Smith  149             610
## 40  GJ Bailey   GJ Maxwell  133             610

11. Partnership runs against opposition (all ODI matches)

The chart below gives the overall partnership. It is graphical representation of the chart above.

batsmanPartnershipOppnChart(allMatches,"India")

partnershipOppnChart,-1

batsmanPartnershipOppnChart(allMatches,"Australia")

partnershipOppnChart,-2

12. Batsmen vs Bowlers against opposition (all ODI matches)

The chart below gives how the batsmen fared against the bowlers of the opposition.)

batsmanVsBowlersOppn(allMatches,"India")

batsmenVsBowlers,-1

batsmanVsBowlersOppn(allMatches,"Australia"

bowlersVsBatsmen,-2

13. Team batting details opposition (all ODI matches)

The table below gives the total runs scores by each batsman and is dsiplayed in descending order. Dhoni, Rohit Sharma and Tendulkar are the top 3 for India and Ponting, Hussey and Bailey lead for Australia

teamBattingDetailsOppn(allMatches,"India")
## Total= 8313
## Source: local data frame [44 x 5]
## 
##         batsman  runs fours sixes ballsPlayed
##          (fctr) (dbl) (int) (int)       (int)
## 1      MS Dhoni  1156    78    22        1406
## 2     RG Sharma   914    72    24        1015
## 3  SR Tendulkar   910   103     6        1157
## 4       V Kohli   902    87     6         961
## 5     G Gambhir   532    43     2         677
## 6  Yuvraj Singh   524    52    11         664
## 7      SK Raina   509    43    11         536
## 8      S Dhawan   471    55     6         470
## 9      V Sehwag   287    42     4         303
## 10   RV Uthappa   279    28     7         295
## ..          ...   ...   ...   ...         ...
teamBattingDetailsOppn(allMatches,"Australia")
## Total= 9993
## Source: local data frame [48 x 5]
## 
##       batsman  runs fours sixes ballsPlayed
##        (fctr) (dbl) (int) (int)       (int)
## 1  RT Ponting   876    86     8        1107
## 2  MEK Hussey   753    56     5         816
## 3   GJ Bailey   610    50    13         578
## 4   SR Watson   609    81    10         653
## 5   MJ Clarke   607    45     5         786
## 6   ML Hayden   573    72     8         660
## 7   A Symonds   536    43    15         543
## 8    AJ Finch   525    52     9         617
## 9   SPD Smith   467    44     7         431
## 10  DA Warner   391    40     6         385
## ..        ...   ...   ...   ...         ...

14. Bowler vs Batsman against opposition (all ODI matches)

The charts below give the performance of the bowlers against batsman

bowlersVsBatsmanOppn(allMatches,"India")

bowlersVsBatsmen,-1

bowlersVsBatsmanOppn(allMatches,"Australia")

bowlersVsBatsmen,-2

15. Bowling details against opposition (all ODI matches)

For matches between Australia and India the top 3 wicket takes for Australia are Mitchell Johnson, Brett Lee and JR Faulkner. For India it is Ishant Sharma, Harbhajan Singh and R A Jadeja.

teamBowlingDetailsOppn(allMatches,"India")
## Source: local data frame [39 x 5]
## 
##          bowler overs maidens  runs wickets
##          (fctr) (int)   (int) (dbl)   (dbl)
## 1    MG Johnson    40       0  1012      18
## 2         B Lee    21       1   667      15
## 3   JP Faulkner    33       0   598      13
## 4     SR Watson    24       0   532      12
## 5       GB Hogg    15       0   427      12
## 6      CJ McKay    17       0   403      12
## 7    NW Bracken    28       2   429      11
## 8      MA Starc    12       2   251      11
## 9      JR Hopes    18       0   346       8
## 10 DE Bollinger    11       4   174       8
## ..          ...   ...     ...   ...     ...
teamBowlingDetailsOppn(allMatches,"Australia")
## Source: local data frame [37 x 5]
## 
##             bowler overs maidens  runs wickets
##             (fctr) (int)   (int) (dbl)   (dbl)
## 1         I Sharma    44       1   739      20
## 2  Harbhajan Singh    40       0   926      15
## 3        RA Jadeja    39       0   867      14
## 4        IK Pathan    42       1   702      11
## 5         UT Yadav    37       2   606      10
## 6          P Kumar    27       0   501      10
## 7           Z Khan    33       1   500      10
## 8      S Sreesanth    34       0   454      10
## 9         R Ashwin    43       0   680       9
## 10   R Vinay Kumar    31       1   380       9
## ..             ...   ...     ...   ...     ...

16. Wicket kind against opposition (all ODI matches)

These charts give the wicket kind for each of the top 9 bowlers from each side.

teamBowlingWicketKindOppn(allMatches,"India")

wicketKindOppn-1

teamBowlingWicketKindOppn(allMatches,"Australia")

wicketKindOppn-2

17. Wicket runs against opposition (all ODI matches)

These given the runs conceded by the bowlers

teamBowlingWicketRunsOppn(allMatches,"India")

wicketRunsOppn-1

teamBowlingWicketRunsOppn(allMatches,"Australia")

wicketRunsOppn-2

18. Wickets against opposition (all ODI matches)

The charts below depict the wickets taken by each bowler. If you notice Mitchel Johnson has the most wickets.

teamBowlingWicketsOppn(allMatches,"India")

wicketOppn,-1

teamBowlingWicketsOppn(allMatches,"Australia")

wicketOppn,-2

Conclusion :

Some key findings

In the ODI confrontations between Australia and India the top 3 batsmen of India are

  1. Mahendra Dhoni 2.Rohit Sharma
  2. Sachin Tendulkar.

The best bowlers for India are

  1. Ishant Sharma
  2. Harbhajan Singh
  3. R A Jadeja

For the Australian side the top 3 batsmen are

  1. R A Ponting
  2. M Hussey
  3. G J Bailey

The top 3 bowlers are

1. Mitchell Johnson
2. Brett Lee
3. J P Faulkner

Note: This is the first part of my yorkr package. I will be adding more functions in the weeks to come. Clearly the data from Cricsheet is more granular and allows for more detailed analyses. I should have the next set of functions soon.

(Take a look at The making of cricket package yorkr – Part 2)

Important note: Do check out my other posts using yorkr at yorkr-posts

Watch this space!!!

Also see

  1. Cricket analytics with cricketr
  2. Introducing cricketr! : An R package to analyze performances of cricketers
  3. Sixer – R package cricketr’s new Shiny avatar
  4. Informed choices through Machine Learning – Analyzing Kohli, Tendulkar and Dravid

You may also like

  1. Natural language processing: What would Shakespeare say?
  2. Revisiting crimes against women in India
  3. Literacy in India – A deepR dive
  4. TWS-4: Gossip protocol: Epidemics and rumors to the rescue
  5. Singularity
  6. Simulating an Edge shape in Android
  7. Programming Zen and now – Sime essential tips
  8. Rock N’ Roll with Bluemix, Cloudant & NodeExpress
  9. Architecting a cloud based IP Multimedia System (IMS)