Pitching yorkpy … short of good length to IPL – Part 1


I fear not the man who has practiced 10,000 kicks once, but I fear the man who has practiced one kick 10,000 times.
Bruce Lee

I’ve missed more than 9000 shots in my career. I’ve lost almost 300 games. 26 times, I’ve been trusted to take the game winning shot and missed. I’ve failed over and over and over again in my life. And that is why I succeed.
Michael Jordan

Man, it doesn’t matter where you come in to bat, the score is still zero
Viv Richards

Introduction

“If cricketr is to cricpy, then yorkr is to _____?”. Yes, you guessed it right, it is yorkpy. In this post, I introduce my 2nd python package, yorkpy, which is a python clone of my R package yorkr. This package is based on data from Cricsheet. yorkpy currently handles IPL T20 matches.

When I created cricpy, the python avatar, of my R package cricketr, see Introducing cricpy:A python package to analyze performances of cricketers, I had decided that I should avoid doing a python avatar of my R package yorkr (see Introducing cricket package yorkr: Part 1- Beaten by sheer pace!) , as it was more involved, and required the parsing of match data available as yaml files.

Just out of curiosity, I tried the python package ‘yaml’ to read the match data, and lo and behold, I was sucked into the developing the package and so, yorkpy was born. Of course, it goes without saying that, usually when I am in the thick of developing something, I occasionally wonder, why I am doing it, for whom and for what purpose? Maybe it is the joy of ideation, the problem-solving,  the programmer’s high, for sharing my ideas etc. Anyway, whatever be the reason, I hope you enjoy this post and also find yorkpy useful.

You can clone/download the code at Github yorkpy
This post has been published to RPubs at yorkpy-Part1
You can download this post as PDF at IPLT20-yorkpy-part1

The IPL T20 functions in yorkpy are

2. Install the package using ‘pip install’

import pandas as pd
import yorkpy.analytics as yka
#pip install yorkpy

3. Load a yaml file from Cricsheet

There are 2 functions that can be to convert the IPL Twenty20 yaml files to pandas dataframeare

  1. convertYaml2PandasDataframeT20
  2. convertAllYaml2PandasDataframesT20

Note 1: While I have already converted the IPL T20 files, you will need to use these functions for future IPL matches

4. Convert and save IPL T20 yaml file to pandas dataframe

This function will convert a IPL T20 IPL yaml file, in the format as specified in Cricsheet to pandas dataframe. This will be saved as as CSV file in the target directory. The name of the file wil have the following format team1-team2-date.csv. The IPL T20 zip file can be downloaded from Indian Premier League matches.  An example of how a yaml file can be converted to a dataframe and saved is shown below.

import pandas as pd
import yorkpy.analytics as yka
#convertYaml2PandasDataframe(".\\1082593.yaml","..\ipl", ..\\data")

5. Convert and save all IPL T20 yaml files to dataframes

This function will convert all IPL 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 yorkpyData

import pandas as pd
import yorkpy.analytics as yka
#convertAllYaml2PandasDataframes("..\\ipl", "..\\data")

You can download the the zip of the files and use it directly in the functions as follows.For the analysis below I chosen a set of random IPL matches

The randomly selected IPL T20 matches are

  • Chennai Super Kings vs Kings Xi Punjab, 2014-05-30
  • Deccan Chargers vs Delhi Daredevils, 2012-05-10
  • Gujarat Lions vs Mumbai Indians, 2017-04-29
  • Kolkata Knight Riders vs Rajasthan Royals, 2010-04-17
  • Rising Pune Supergiants vs Royal Challengers Bangalore, 2017-04-29

6. Team batting scorecard

The function below computes the batting score card of a team in an IPL match. The scorecard gives the balls faced, the runs scored, 4s, 6s and strike rate. The example below is based on the CSK KXIP match on 30 May 2014.

You can check against the actual scores in this match Chennai Super Kings-Kings XI Punjab-2014-05-30

import pandas as pd
import yorkpy.analytics as yka
csk_kxip=pd.read_csv(".\\Chennai Super Kings-Kings XI Punjab-2014-05-30.csv")
scorecard,extras=yka.teamBattingScorecardMatch(csk_kxip,"Chennai Super Kings")
print(scorecard)
##         batsman  runs  balls  4s  6s          SR
## 0      DR Smith     7     12   0   0   58.333333
## 1  F du Plessis     0      1   0   0    0.000000
## 2      SK Raina    87     26  12   0  334.615385
## 3   BB McCullum    11     16   0   0   68.750000
## 4     RA Jadeja    27     22   2   0  122.727273
## 5     DJ Hussey     1      3   0   0   33.333333
## 6      MS Dhoni    42     34   3   0  123.529412
## 7      R Ashwin    10     11   0   0   90.909091
## 8     MM Sharma     1      3   0   0   33.333333
print(extras)
##    total  wides  noballs  legbyes  byes  penalty  extras
## 0    428     14        3        5     5        0      27
print("\n\n")
scorecard1,extras1=yka.teamBattingScorecardMatch(csk_kxip,"Kings XI Punjab")
print(scorecard1)
##       batsman  runs  balls  4s  6s          SR
## 0    V Sehwag   122     62  12   0  196.774194
## 1     M Vohra    34     33   1   0  103.030303
## 2  GJ Maxwell    13      8   1   0  162.500000
## 3   DA Miller    38     19   5   0  200.000000
## 4   GJ Bailey     1      2   0   0   50.000000
## 5     WP Saha     6      4   0   0  150.000000
## 6  MG Johnson     1      1   0   0  100.000000
print(extras1)
##    total  wides  noballs  legbyes  byes  penalty  extras
## 0    428     14        3        5     5        0      27

Let’s take another random match between Gujarat Lions and Mumbai Indian on 29 Apr 2017 Gujarat Lions-Mumbai Indians-2017-04-29

import pandas as pd
gl_mi=pd.read_csv(".\\Gujarat Lions-Mumbai Indians-2017-04-29.csv")
import yorkpy.analytics as yka
scorecard,extras=yka.teamBattingScorecardMatch(gl_mi,"Gujarat Lions")
print(scorecard)
##          batsman  runs  balls  4s  6s          SR
## 0   Ishan Kishan    48     38   6   0  126.315789
## 1    BB McCullum     6      4   1   0  150.000000
## 2       SK Raina     1      3   0   0   33.333333
## 3       AJ Finch     0      3   0   0    0.000000
## 4     KD Karthik     2      9   0   0   22.222222
## 5      RA Jadeja    28     22   2   0  127.272727
## 6    JP Faulkner    21     29   2   0   72.413793
## 7      IK Pathan     2      3   0   0   66.666667
## 8         AJ Tye    25     12   2   0  208.333333
## 9   Basil Thampi     2      4   0   0   50.000000
## 10    Ankit Soni     7      2   0   0  350.000000
print(extras)
##    total  wides  noballs  legbyes  byes  penalty  extras
## 0    306      8        3        1     0        0      12
print("\n\n")
scorecard1,extras1=yka.teamBattingScorecardMatch(gl_mi,"Mumbai Indians")
print(scorecard1)
##             batsman  runs  balls  4s  6s          SR
## 0          PA Patel    70     45   9   0  155.555556
## 1        JC Buttler     9      7   2   0  128.571429
## 2            N Rana    19     16   1   0  118.750000
## 3         RG Sharma     5     13   0   0   38.461538
## 4        KA Pollard    15     11   2   0  136.363636
## 5         KH Pandya    29     20   2   0  145.000000
## 6         HH Pandya     4      5   0   0   80.000000
## 7   Harbhajan Singh     0      1   0   0    0.000000
## 8    MJ McClenaghan     1      1   0   0  100.000000
## 9         JJ Bumrah     0      1   0   0    0.000000
## 10       SL Malinga     0      1   0   0    0.000000
print(extras1)
##    total  wides  noballs  legbyes  byes  penalty  extras
## 0    306      8        3        1     0        0      12

7. Plot the team batting partnerships

The functions below plot the team batting partnership in the match. It shows what the partnership were in the mtach

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 chart using one of the packages like rcharts, ggvis,googleVis or plotly.

import pandas as pd
import yorkpy.analytics as yka
dc_dd=pd.read_csv(".\\Deccan Chargers-Delhi Daredevils-2012-05-10.csv")
yka.teamBatsmenPartnershipMatch(dc_dd,'Deccan Chargers','Delhi Daredevils')

yka.teamBatsmenPartnershipMatch(dc_dd,'Delhi Daredevils','Deccan Chargers',plot=True)
# Print partnerships as a dataframe

rps_rcb=pd.read_csv(".\\Rising Pune Supergiant-Royal Challengers Bangalore-2017-04-29.csv")
m=yka.teamBatsmenPartnershipMatch(rps_rcb,'Royal Challengers Bangalore','Rising Pune Supergiant',plot=False)
print(m)
##            batsman     non_striker  runs
## 0   AB de Villiers         V Kohli     3
## 1         AF Milne         V Kohli     5
## 2        KM Jadhav         V Kohli     7
## 3           P Negi         V Kohli     3
## 4        S Aravind         V Kohli     0
## 5        S Aravind       YS Chahal     8
## 6         S Badree         V Kohli     2
## 7        STR Binny         V Kohli     1
## 8      Sachin Baby         V Kohli     2
## 9          TM Head         V Kohli     2
## 10         V Kohli  AB de Villiers    17
## 11         V Kohli        AF Milne     5
## 12         V Kohli       KM Jadhav     4
## 13         V Kohli          P Negi     9
## 14         V Kohli       S Aravind     2
## 15         V Kohli        S Badree     8
## 16         V Kohli     Sachin Baby     1
## 17         V Kohli         TM Head     9
## 18       YS Chahal       S Aravind     4

8. 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

import pandas as pd
import yorkpy.analytics as yka
gl_mi=pd.read_csv(".\\Gujarat Lions-Mumbai Indians-2017-04-29.csv")
yka.teamBatsmenVsBowlersMatch(gl_mi,"Gujarat Lions","Mumbai Indians", plot=True)
# Print 

csk_kxip=pd.read_csv(".\\Chennai Super Kings-Kings XI Punjab-2014-05-30.csv")
m=yka.teamBatsmenVsBowlersMatch(csk_kxip,'Chennai Super Kings','Kings XI Punjab',plot=False)
print(m)
##          batsman           bowler  runs
## 0    BB McCullum         AR Patel     4
## 1    BB McCullum       GJ Maxwell     1
## 2    BB McCullum  Karanveer Singh     6
## 3      DJ Hussey          P Awana     1
## 4       DR Smith       MG Johnson     7
## 5       DR Smith          P Awana     0
## 6       DR Smith   Sandeep Sharma     0
## 7   F du Plessis       MG Johnson     0
## 8      MM Sharma         AR Patel     0
## 9      MM Sharma       MG Johnson     0
## 10     MM Sharma          P Awana     1
## 11      MS Dhoni         AR Patel    12
## 12      MS Dhoni  Karanveer Singh     2
## 13      MS Dhoni       MG Johnson    11
## 14      MS Dhoni          P Awana    15
## 15      MS Dhoni   Sandeep Sharma     2
## 16      R Ashwin         AR Patel     1
## 17      R Ashwin  Karanveer Singh     4
## 18      R Ashwin       MG Johnson     1
## 19      R Ashwin          P Awana     1
## 20      R Ashwin   Sandeep Sharma     3
## 21     RA Jadeja         AR Patel     5
## 22     RA Jadeja       GJ Maxwell     3
## 23     RA Jadeja  Karanveer Singh    19
## 24     RA Jadeja          P Awana     0
## 25      SK Raina       MG Johnson    21
## 26      SK Raina          P Awana    40
## 27      SK Raina   Sandeep Sharma    26

9. Bowling Scorecard

This function provides the bowling performance, the number of overs bowled, maidens, runs conceded. wickets taken and economy rate for the IPL match

import pandas as pd
import yorkpy.analytics as yka
dc_dd=pd.read_csv(".\\Deccan Chargers-Delhi Daredevils-2012-05-10.csv")
a=yka.teamBowlingScorecardMatch(dc_dd,'Deccan Chargers')
print(a)
##        bowler  overs  runs  maidens  wicket  econrate
## 0  AD Russell      4    39        0       0      9.75
## 1   IK Pathan      4    46        0       1     11.50
## 2    M Morkel      4    32        0       1      8.00
## 3    S Nadeem      4    39        0       0      9.75
## 4    VR Aaron      4    30        0       2      7.50
rps_rcb=pd.read_csv(".\\Rising Pune Supergiant-Royal Challengers Bangalore-2017-04-29.csv")
b=yka.teamBowlingScorecardMatch(rps_rcb,'Royal Challengers Bangalore')
print(b)
##               bowler  overs  runs  maidens  wicket  econrate
## 0          DL Chahar      2    18        0       0      9.00
## 1       DT Christian      4    25        0       1      6.25
## 2        Imran Tahir      4    18        0       3      4.50
## 3         JD Unadkat      4    19        0       1      4.75
## 4        LH Ferguson      4     7        1       3      1.75
## 5  Washington Sundar      2     7        0       1      3.50

10. Wicket Kind

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

import pandas as pd
import yorkpy.analytics as yka
kkr_rr=pd.read_csv(".\\Kolkata Knight Riders-Rajasthan Royals-2010-04-17.csv")
yka.teamBowlingWicketKindMatch(kkr_rr,'Kolkata Knight Riders','Rajasthan Royals')

csk_kxip=pd.read_csv(".\\Chennai Super Kings-Kings XI Punjab-2014-05-30.csv")
m = yka.teamBowlingWicketKindMatch(csk_kxip,'Chennai Super Kings','Kings-Kings XI Punjab',plot=False)
print(m)
##             bowler     kind  player_out
## 0         AR Patel  run out           1
## 1         AR Patel  stumped           1
## 2  Karanveer Singh  run out           1
## 3       MG Johnson   caught           1
## 4          P Awana   caught           2
## 5   Sandeep Sharma   bowled           1

11. Wicket vs Runs conceded

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

import pandas as pd
import yorkpy.analytics as yka
dc_dd=pd.read_csv(".\\Deccan Chargers-Delhi Daredevils-2012-05-10.csv")
yka.teamBowlingWicketMatch(dc_dd,"Deccan Chargers", "Delhi Daredevils",plot=True)

print("\n\n")
rps_rcb=pd.read_csv(".\\Rising Pune Supergiant-Royal Challengers Bangalore-2017-04-29.csv")
a=yka.teamBowlingWicketMatch(rps_rcb,"Royal Challengers Bangalore", "Rising Pune Supergiant",plot=False)
print(a)
##               bowler      player_out  kind
## 0       DT Christian         V Kohli     1
## 1        Imran Tahir        AF Milne     1
## 2        Imran Tahir          P Negi     1
## 3        Imran Tahir        S Badree     1
## 4         JD Unadkat         TM Head     1
## 5        LH Ferguson  AB de Villiers     1
## 6        LH Ferguson       KM Jadhav     1
## 7        LH Ferguson       STR Binny     1
## 8  Washington Sundar     Sachin Baby     1

12. Bowler Vs Batsmen

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

import pandas as pd
import yorkpy.analytics as yka
csk_kxip=pd.read_csv(".\\Chennai Super Kings-Kings XI Punjab-2014-05-30.csv")
yka.teamBowlersVsBatsmenMatch(csk_kxip,"Chennai Super Kings","Kings XI Punjab")

print("\n\n")
kkr_rr=pd.read_csv(".\\Kolkata Knight Riders-Rajasthan Royals-2010-04-17.csv")
m =yka.teamBowlersVsBatsmenMatch(kkr_rr,"Rajasthan Royals","Kolkata Knight Riders",plot=False)
print(m)
##        batsman      bowler  runs
## 0     AC Voges    AB Dinda     1
## 1     AC Voges  JD Unadkat     1
## 2     AC Voges   LR Shukla     1
## 3     AC Voges    M Kartik     5
## 4     AJ Finch    AB Dinda     3
## 5     AJ Finch  JD Unadkat     3
## 6     AJ Finch   LR Shukla    13
## 7     AJ Finch    M Kartik     2
## 8     AJ Finch     SE Bond     0
## 9      AS Raut    AB Dinda     1
## 10     AS Raut  JD Unadkat     1
## 11    FY Fazal    AB Dinda     1
## 12    FY Fazal   LR Shukla     3
## 13    FY Fazal    M Kartik     3
## 14    FY Fazal     SE Bond     6
## 15     NV Ojha    AB Dinda    10
## 16     NV Ojha  JD Unadkat     5
## 17     NV Ojha   LR Shukla     0
## 18     NV Ojha    M Kartik     1
## 19     NV Ojha     SE Bond     2
## 20     P Dogra  JD Unadkat     2
## 21     P Dogra   LR Shukla     5
## 22     P Dogra    M Kartik     1
## 23     P Dogra     SE Bond     0
## 24  SK Trivedi    AB Dinda     4
## 25    SK Warne    AB Dinda     2
## 26    SK Warne    M Kartik     1
## 27    SK Warne     SE Bond     0
## 28   SR Watson    AB Dinda     2
## 29   SR Watson  JD Unadkat    13
## 30   SR Watson   LR Shukla     1
## 31   SR Watson    M Kartik    18
## 32   SR Watson     SE Bond    10
## 33   YK Pathan  JD Unadkat     1
## 34   YK Pathan   LR Shukla     7

13. Match worm chart

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

import pandas as pd
import yorkpy.analytics as yka
dc_dd=pd.read_csv(".\\Deccan Chargers-Delhi Daredevils-2012-05-10.csv")
yka.matchWormChart(dc_dd,"Deccan Chargers", "Delhi Daredevils")

gl_mi=pd.read_csv(".\\Gujarat Lions-Mumbai Indians-2017-04-29.csv")
yka.matchWormChart(gl_mi,"Mumbai Indians","Gujarat Lions")

Feel free to clone/download the code from Github yorkpy

Conclusion

This post included all functions between 2 IPL teams from the package yorkpy for IPL Twenty20 matches. As mentioned above the yaml match files have been already converted to dataframes and are available for download from Github at yorkpyData

After having used Python and R for analytics, Machine Learning and Deep Learning, I have now realized that neither language is superior or inferior. Both have, some good packages and some that are not so well suited.

To be continued. Watch this space!

You may also like
1.My book ‘Deep Learning from first principles:Second Edition’ now on Amazon
2.My book ‘Practical Machine Learning in R and Python: Second edition’ on Amazon
2. Cricpy takes a swing at the ODIs
3. Introducing cricket package yorkr: Part 1- Beaten by sheer pace!
4. Big Data-1: Move into the big league:Graduate from Python to Pyspark
5. Simulating an Edge Shape in Android

To see all posts click Index of posts

Using Linear Programming (LP) for optimizing bowling change or batting lineup in T20 cricket


In my recent post, My travels through the realms of Data Science, Machine Learning, Deep Learning and (AI), I had recounted my journey in the domains of of Data Science, Machine Learning (ML), and more recently Deep Learning (DL) all of which are useful while analyzing data. Of late, I have come to the realization that there are many facets to data. And to glean insights from data, Data Science, ML and DL alone are not sufficient and one needs to also have a good handle on linear programming and optimization. My colleague at IBM Research also concurred with this view and told me he had arrived at this conclusion several years ago.

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

While ML & DL are very useful and interesting to make inferences and predictions of outputs from input variables, optimization computes the choice of input which results in maximizing or minimizing the output. So I made a small course correction and started on a course from India’s own NPTEL Introduction to Linear Programming by Prof G. Srinivasan of IIT Madras (highly recommended!). The lectures are delivered with remarkable clarity by the Prof and I am just about halfway through the course (each lecture is of 50-55 min duration), when I decided that I needed to try to formulate and solve some real world Linear Programming problem.

As usual, I turned towards cricket for some appropriate situations, and sure enough it was there in the open. For this LP formulation I take International T20 and IPL, though International ODI will also work equally well.  You can download the associated code and data for this from Github at LP-cricket-analysis

In T20 matches the captain has to make choice of how to rotate bowlers with the aim of restricting the batting side. Conversely, the batsmen need to take advantage of the bowling strength to maximize the runs scored.

Note:
a) A simple and obvious strategy would be
– If the ith bowler’s economy rate is less than the economy rate of the jth bowler i.e.
er_{i} < er_{j} then have bowler ‘i’ to bowl more overs as his/her economy rate is better

b)A better strategy would be to consider the economy rate of each bowler against each batsman. How often  have we witnessed bowlers with a great bowling average get thrashed time and again by the same batsman, or a bowler who is generally very poor being very effective against a particular batsman. i.e. er_{ij} < er_{ik} where the jth bowler is more effective than the kth bowler against the ith batsman. This now becomes a linear optimization problem as we can have several combinations of number of overs X economy rate for different bowlers and we will have to solve this algorithmically to determine the lowest score for bowling performance or highest score for batting order.

This post uses the latter approach to optimize bowling change and batting lineup.

Let is take a hypothetical situation
Assume there are 3 bowlers – bwlr_{1},bwlr_{2},bwlr_{3}
and there are 4 batsmen – bman_{1},bman_{2},bman_{3},bman_{4}

Let the economy rate er_{ij} be the Economy Rate of the jth bowler to the ith batsman. Also if remaining overs for the bowlers are o_{1},o_{2},o_{3}
and the total number of overs left to be bowled are
o_{1}+o_{2}+o_{3} = N then the question is

a) Given the economy rate of each bowler per batsman, how many overs should each bowler bowl, so that the total runs scored by all the batsmen are minimum?

b) Alternatively, if the know the individual strike rate of a batsman against the individual bowlers, how many overs should each batsman face with a bowler so that the total runs scored is maximized?

1. LP Formulation for bowling order

Let the economy rate er_{ij} be the Economy Rate of the jth bowler to the ith batsman.
Objective function : Minimize –
er_{11}*o_{11} + er_{12}*o_{12} +..+er_{1n}*o_{1n}+ er_{21}*o_{21} + er_{22}*o_{22}+.. + er_{22}*o_{2n}+ er_{m1}*o_{m1}+..+ er_{mn}*o_{mn}
i.e.
\sum_{i=1}^{i=m}\sum_{j=1}^{i=n}er_{ij}*o_{ij}
Constraints
Where o_{j} is the number of overs remaining for the jth bowler against  ‘k’ batsmen
o_{j1} + o_{j2} + .. o_{jk} < o_{j}
and if the total number of overs remaining to be bowled is N then
o_{1} + o_{2} +...+ o_{k} = N or
\sum_{j=1}^{j=k} o_{j} =N
The overs that any bowler can bowl is o_{j} >=0

2. LP Formulation for batting lineup

Let the strike rate sr_{ij}  be the Strike Rate of the ith batsman to the jth bowler
Objective function : Maximize –
sr_{11}*o_{11} + sr_{12}*o_{12} +..+ sr_{1n}*o_{1n}+ sr_{21}*o_{21} + sr_{22}*o_{22}+.. sr_{2n}*o_{2n}+ sr_{m1}*o_{m1}+..+ sr_{mn}*o_{mn}
i.e.
\sum_{i=1}^{i=4}\sum_{j=1}^{i=3}sr_{ij}*o_{ij}
Constraints
Where o_{j} is the number of overs remaining for the jth bowler against  ‘k’ batsmen
o_{j1} + o_{j2} + .. o_{jk} < o_{j}
and the total number of overs remaining to be bowled is N then
o_{1} + o_{2} +...+ o_{k} = N or
\sum_{j=1}^{j=k} o_{j} =N
The overs that any bowler can bowl is
o_{j} >=0

lpSolveAPI– For this maximization and minimization problem I used lpSolveAPI.

Below I take 2 simple examples (example1 & 2)  to ensure that my LP formulation and solution is correct before applying it on real T20 cricket data (Intl. T20 and IPL)

3. LP formulation (Example 1)

Initially I created a test example to ensure that I get the LP formulation and solution correct. Here the er1=4 and er2=3 and o1 & o2 are the overs bowled by bowlers 1 & 2. Also o1+o2=4 In this example as below

o1 o2 Obj Fun(=4o1+3o2)
1    3      13
2    2      14
3    1      15

library(lpSolveAPI)
library(dplyr)
library(knitr)
lprec <- make.lp(0, 2)
a <-lp.control(lprec, sense="min")
set.objfn(lprec, c(4, 3))  # Economy Rate of 4 and 3 for er1 and er2
add.constraint(lprec, c(1, 1), "=",4)  # o1 + o2 =4
add.constraint(lprec, c(1, 0), ">",1)  # o1 > 1
add.constraint(lprec, c(0, 1), ">",1)  # o2 > 1
lprec
## Model name: 
##             C1    C2       
## Minimize     4     3       
## R1           1     1   =  4
## R2           1     0  >=  1
## R3           0     1  >=  1
## Kind       Std   Std       
## Type      Real  Real       
## Upper      Inf   Inf       
## Lower        0     0
b <-solve(lprec)
get.objective(lprec) # 13
## [1] 13
get.variables(lprec) # 1    3 
## [1] 1 3

Note 1: In the above example 13 runs is the minimum that can be scored and this requires

LP solution:
Minimum runs=13

  • o1=1
  • o2=3

Note 2:The numbers in the columns represent the number of overs that need to be bowled by a bowler to the corresponding batsman.

4. LP formulation (Example 2)

In this formulation there are 2 bowlers and 2 batsmen o11,o12 are the oves bowled by bowler 1 to batsmen 1 & 2 and o21, o22 are the overs bowled by bowler 2 to batsmen 1 & 2 er11=4, er12=2,er21=2,er22=5 o11+o12+o21+o22=5

The solution for this manually computed is o11, o12, o21, o22 Runs
where B11, B12 are the overs bowler 1 bowls to batsman 1 and B21 and B22 are overs bowler 2 bowls to batsman 2

o11     o12    o21    o22      Runs=(4*o11+2*o12+2*o21+5*o22)
1            1             1            2           18
1           2              1             1           15
2           1              1            1            17
1           1               2            1            15

lprec <- make.lp(0, 4)
a <-lp.control(lprec, sense="min")
set.objfn(lprec, c(4, 2,2,5))
add.constraint(lprec, c(1, 1,0,0), "<=",8)
add.constraint(lprec, c(0, 0,1,1), "<=",7)
add.constraint(lprec, c(1, 1,1,1), "=",5)
add.constraint(lprec, c(1, 0,0,0), ">",1)
add.constraint(lprec, c(0, 1,0,0), ">",1)
add.constraint(lprec, c(0, 0,1,0), ">",1)
add.constraint(lprec, c(0, 0,0,1), ">",1)
lprec
## Model name: 
##             C1    C2    C3    C4       
## Minimize     4     2     2     5       
## R1           1     1     0     0  <=  8
## R2           0     0     1     1  <=  7
## R3           1     1     1     1   =  5
## R4           1     0     0     0  >=  1
## R5           0     1     0     0  >=  1
## R6           0     0     1     0  >=  1
## R7           0     0     0     1  >=  1
## Kind       Std   Std   Std   Std       
## Type      Real  Real  Real  Real       
## Upper      Inf   Inf   Inf   Inf       
## Lower        0     0     0     0
b<-solve(lprec)
get.objective(lprec) 
## [1] 15
get.variables(lprec) 
## [1] 1 2 1 1

Note: In the above example 15 runs is the minimum that can be scored and this requires

LP Solution:
Minimum runs=15

  • o11=1
  • o12=2
  • o21=1
  • o22=1

It is possible to keep the minimum to other values and solves also.

5. LP formulation for International T20 India vs Australia (Batting lineup)

To analyze batting and bowling lineups in the cricket world I needed to get the ball-by-ball details of runs scored by each batsman against each of the bowlers. Fortunately I had already created this with my R package yorkr. yorkr processes yaml data from Cricsheet. So I copied the data of all matches between Australia and India in International T20s. You can download my processed data for International T20 at Inswinger

load("Australia-India-allMatches.RData")
dim(matches)
## [1] 3541   25

The following functions compute the ‘Strike Rate’ of a batsman as

SR=1/oversRunsScored

Also the Economy Rate is computed as

ER=1/oversRunsConceded

Incidentally the SR=ER

# Compute the Strike Rate of the batsman
computeSR <- function(batsman1,bowler1){
    a <- matches %>% filter(batsman==batsman1 & bowler==bowler1) 
    a1 <- a %>% summarize(totalRuns=sum(runs),count=n()) %>% mutate(SR=(totalRuns/count)*6)
    a1
}

# Compute the Economy Rate of the batsman
computeER <- function(batsman1,bowler1){
    a <- matches %>% filter(batsman==batsman1 & bowler==bowler1) 
    a1 <- a %>% summarize(totalRuns=sum(runs),count=n()) %>% mutate(ER=(totalRuns/count)*6)
    a1
}

Here I compute the Strike Rate of Virat Kohli, Yuvraj Singh and MS Dhoni against Shane Watson, Brett Lee and MA Starc

 # Kohli
kohliWatson<- computeSR("V Kohli","SR Watson")
kohliWatson
##   totalRuns count       SR
## 1        45    37 7.297297
kohliLee <- computeSR("V Kohli","B Lee")
kohliLee
##   totalRuns count       SR
## 1        10     7 8.571429
kohliStarc <- computeSR("V Kohli","MA Starc")
kohliStarc
##   totalRuns count       SR
## 1        11     9 7.333333
# Yuvraj
yuvrajWatson<- computeSR("Yuvraj Singh","SR Watson")
yuvrajWatson
##   totalRuns count       SR
## 1        24    22 6.545455
yuvrajLee <- computeSR("Yuvraj Singh","B Lee")
yuvrajLee
##   totalRuns count       SR
## 1        12     7 10.28571
yuvrajStarc <- computeSR("Yuvraj Singh","MA Starc")
yuvrajStarc
##   totalRuns count SR
## 1        12     8  9
# MS Dhoni
dhoniWatson<- computeSR("MS Dhoni","SR Watson")
dhoniWatson
##   totalRuns count       SR
## 1        33    28 7.071429
dhoniLee <- computeSR("MS Dhoni","B Lee")
dhoniLee
##   totalRuns count  SR
## 1        26    20 7.8
dhoniStarc <- computeSR("MS Dhoni","MA Starc")
dhoniStarc
##   totalRuns count   SR
## 1        11     8 8.25

When we consider the batting lineup, the problem is one of maximization. In the LP formulation below V Kohli has a SR of 7.29, 8.57, 7.33 against Watson, Lee & Starc
Yuvraj has a SR of 6.5, 10.28, 9 against Watson, Lee & Starc
and Dhoni has a SR of 7.07, 7.8,  8.25 against Watson, Lee and Starc

The constraints are Watson, Lee and Starc have 3, 4 & 3 overs remaining respectively. The total number of overs remaining to be bowled is 9.The other constraints could be that a bowler bowls at least 1 over etc.

Formulating and solving

# 3 batsman x 3 bowlers
lprec <- make.lp(0, 9)
# Maximization
a<-lp.control(lprec, sense="max")

# Set the objective function
set.objfn(lprec, c(kohliWatson$SR, kohliLee$SR,kohliStarc$SR,
                   yuvrajWatson$SR,yuvrajLee$SR,yuvrajStarc$SR,
                   dhoniWatson$SR,dhoniLee$SR,dhoniStarc$SR))

#Assume the  bowlers have 3,4,3 overs left respectively
add.constraint(lprec, c(1, 1,1,0,0,0, 0,0,0), "<=",3)
add.constraint(lprec, c(0,0,0,1,1,1,0,0,0), "<=",4)
add.constraint(lprec, c(0,0,0,0,0,0,1,1,1), "<=",3)
#o11+o12+o13+o21+o22+o23+o31+o32+o33=8 (overs remaining)
add.constraint(lprec, c(1,1,1,1,1,1,1,1,1), "=",9) 


add.constraint(lprec, c(1,0,0,0,0,0,0,0,0), ">=",1) #o11 >=1
add.constraint(lprec, c(0,1,0,0,0,0,0,0,0), ">=",0) #o12 >=0
add.constraint(lprec, c(0,0,1,0,0,0,0,0,0), ">=",0) #o13 >=0
add.constraint(lprec, c(0,0,0,1,0,0,0,0,0), ">=",1) #o21 >=1
add.constraint(lprec, c(0,0,0,0,1,0,0,0,0), ">=",1) #o22 >=1
add.constraint(lprec, c(0,0,0,0,0,1,0,0,0), ">=",0) #o23 >=0
add.constraint(lprec, c(0,0,0,0,0,0,1,0,0), ">=",1) #o31 >=1
add.constraint(lprec, c(0,0,0,0,0,0,0,1,0), ">=",0) #o32 >=0
add.constraint(lprec, c(0,0,0,0,0,0,0,0,1), ">=",0) #o33 >=0

lprec
## Model name: 
##   a linear program with 9 decision variables and 13 constraints
b <-solve(lprec)
get.objective(lprec) #  
## [1] 77.16418
get.variables(lprec) # 
## [1] 1 2 0 1 3 0 1 0 1

This shows that the maximum runs that can be scored for the current strike rate is 77.16   runs in 9 overs The breakup is as follows

This is also shown below

get.variables(lprec) # 
## [1] 1 2 0 1 3 0 1 0 1

This is also shown below

e <- as.data.frame(rbind(c(1,2,0,3),c(1,3,0,4),c(1,0,1,2)))
names(e) <- c("S Watson","B Lee","MA Starc","Overs")
rownames(e) <- c("Kohli","Yuvraj","Dhoni")
e

LP Solution:
Maximum runs that can be scored by India against Australia is:77.164 if the 9 overs to be faced by the batsman are as below

##        S Watson B Lee MA Starc Overs
## Kohli         1     2        0     3
## Yuvraj        1     3        0     4
## Dhoni         1     0        1     2
#Total overs=9

Note: This assumes that the batsmen perform at their current Strike Rate. Howvever anything can happen in a real game, but nevertheless this is a fairly reasonable estimate of the performance

Note 2:The numbers in the columns represent the number of overs that need to be bowled by a bowler to the corresponding batsman.

Note 3:You could try other combinations of overs for the above SR. For the above constraints 77.16 is the highest score for the given number of overs

6. LP formulation for International T20 India vs Australia (Bowling lineup)

For this I compute how the bowling should be rotated between R Ashwin, RA Jadeja and JJ Bumrah when taking into account their performance against batsmen like Shane Watson, AJ Finch and David Warner. For the bowling performance I take the Economy rate of the bowlers. The data is the same as above

computeSR <- function(batsman1,bowler1){
    a <- matches %>% filter(batsman==batsman1 & bowler==bowler1) 
    a1 <- a %>% summarize(totalRuns=sum(runs),count=n()) %>% mutate(SR=(totalRuns/count)*6)
    a1
}
# RA Jadeja
jadejaWatson<- computeER("SR Watson","RA Jadeja")
jadejaWatson
##   totalRuns count       ER
## 1        60    29 12.41379
jadejaFinch <- computeER("AJ Finch","RA Jadeja")
jadejaFinch
##   totalRuns count       ER
## 1        36    33 6.545455
jadejaWarner <- computeER("DA Warner","RA Jadeja")
jadejaWarner
##   totalRuns count       ER
## 1        23    11 12.54545
# Ashwin
ashwinWatson<- computeER("SR Watson","R Ashwin")
ashwinWatson
##   totalRuns count       ER
## 1        41    26 9.461538
ashwinFinch <- computeER("AJ Finch","R Ashwin")
ashwinFinch
##   totalRuns count   ER
## 1        63    36 10.5
ashwinWarner <- computeER("DA Warner","R Ashwin")
ashwinWarner
##   totalRuns count       ER
## 1        38    28 8.142857
# JJ Bunrah
bumrahWatson<- computeER("SR Watson","JJ Bumrah")
bumrahWatson
##   totalRuns count  ER
## 1        22    20 6.6
bumrahFinch <- computeER("AJ Finch","JJ Bumrah")
bumrahFinch
##   totalRuns count       ER
## 1        25    19 7.894737
bumrahWarner <- computeER("DA Warner","JJ Bumrah")
bumrahWarner
##   totalRuns count ER
## 1         2     4  3

As can be seen from above RA Jadeja has a ER of 12.4, 6.54, 12.54 against Watson, AJ Finch and Warner also Ashwin has a ER of 9.46, 10.5, 8.14 against Watson, Finch and Warner. Similarly Bumrah has an ER of 6.6,7.89, 3 against Watson, Finch and Warner
The constraints are Jadeja, Ashwin and Bumrah have 4, 3 & 4 overs remaining and the total overs remaining to be bowled is 10.

Formulating solving the bowling lineup is shown below

lprec <- make.lp(0, 9)
a <-lp.control(lprec, sense="min")

# Set the objective function
set.objfn(lprec, c(jadejaWatson$ER, jadejaFinch$ER,jadejaWarner$ER,
                   ashwinWatson$ER,ashwinFinch$ER,ashwinWarner$ER,
                   bumrahWatson$ER,bumrahFinch$ER,bumrahWarner$ER))

add.constraint(lprec, c(1, 1,1,0,0,0, 0,0,0), "<=",4) # Jadeja has 4 overs
add.constraint(lprec, c(0,0,0,1,1,1,0,0,0), "<=",3)   # Ashwin has 3 overs left
add.constraint(lprec, c(0,0,0,0,0,0,1,1,1), "<=",4)   # Bumrah has 4 overs left
add.constraint(lprec, c(1,1,1,1,1,1,1,1,1), "=",10) # Total overs = 10
add.constraint(lprec, c(1,0,0,0,0,0,0,0,0), ">=",1)
add.constraint(lprec, c(0,1,0,0,0,0,0,0,0), ">=",0)
add.constraint(lprec, c(0,0,1,0,0,0,0,0,0), ">=",1)
add.constraint(lprec, c(0,0,0,1,0,0,0,0,0), ">=",0)
add.constraint(lprec, c(0,0,0,0,1,0,0,0,0), ">=",1)
add.constraint(lprec, c(0,0,0,0,0,1,0,0,0), ">=",0)
add.constraint(lprec, c(0,0,0,0,0,0,1,0,0), ">=",0)
add.constraint(lprec, c(0,0,0,0,0,0,0,1,0), ">=",1)
add.constraint(lprec, c(0,0,0,0,0,0,0,0,1), ">=",0)

lprec
## Model name: 
##   a linear program with 9 decision variables and 13 constraints
b <-solve(lprec)
get.objective(lprec) #  
## [1] 73.58775
get.variables(lprec) # 
## [1] 1 2 1 0 1 1 0 1 3

The minimum runs that will be conceded by these 3 bowlers in 10 overs is 73.58 assuming the bowling is rotated as follows

e <- as.data.frame(rbind(c(1,0,0),c(2,1,1),c(1,1,3),c(4,2,4)))
names(e) <- c("RA Jadeja","R Ashwin","JJ Bumrah")
rownames(e) <- c("S Watson","AJ Finch","DA Warner","Overs")
e 

LP Solution:
Minimum runs that will be conceded by India against Australia is 73.58 in 10 overs if the overs bowled are as follows

##           RA Jadeja R Ashwin JJ Bumrah
## S Watson          1        0         0
## AJ Finch          2        1         1
## DA Warner         1        1         3
## Overs             4        2         4
#Total overs=10  

7. LP formulation for IPL (Mumbai Indians – Kolkata Knight Riders – Bowling lineup)

As in the case of International T20s I also have processed IPL data derived from my R package yorkr. yorkr. yorkr processes yaml data from Cricsheet. The processed data for all IPL matches can be downloaded from GooglyPlus

load("Mumbai Indians-Kolkata Knight Riders-allMatches.RData")
dim(matches)
## [1] 4237   25
# Compute the Economy Rate of the Mumbai Indian bowlers against Kolkata Knight Riders

# Gambhir
gambhirMalinga <- computeER("G Gambhir","SL Malinga")
gambhirHarbhajan <- computeER("G Gambhir","Harbhajan Singh")
gambhirPollard <- computeER("G Gambhir","KA Pollard")

#Yusuf Pathan
yusufMalinga <- computeER("YK Pathan","SL Malinga")
yusufHarbhajan <- computeER("YK Pathan","Harbhajan Singh")
yusufPollard <- computeER("YK Pathan","KA Pollard")

#JH Kallis
kallisMalinga <- computeER("JH Kallis","SL Malinga")
kallisHarbhajan <- computeER("JH Kallis","Harbhajan Singh")
kallisPollard <- computeER("JH Kallis","KA Pollard")

#RV Uthappa
uthappaMalinga <- computeER("RV Uthappa","SL Malinga")
uthappaHarbhajan <- computeER("RV Uthappa","Harbhajan Singh")
uthappaPollard <- computeER("RV Uthappa","KA Pollard")

Here

gambhirMalinga, yusufMalinga, kallisMalinga, uthappaMalinga is the ER of Malinga against Gambhir, Yusuf Pathan, Kallis and Uthappa
gambhirHarbhajan, yusufHarbhajan, kallisHarbhajan, uthappaHarbhajan is the ER of Harbhajan against Gambhir, Yusuf Pathan, Kallis and Uthappa
gambhirPollard, yusufPollard, kallisPollard, uthappaPollard is the ER of Kieron Pollard against Gambhir, Yusuf Pathan, Kallis and Uthappa

The constraints are Malinga, Harbhajan and Pollard have 4 overs each and remaining overs to be bowled is 10.

Formulating and solving this for the bowling lineup of Mumbai Indians against Kolkata Knight Riders

 library("lpSolveAPI")
 lprec <- make.lp(0, 12)
 a=lp.control(lprec, sense="min")
 
 set.objfn(lprec, c(gambhirMalinga$ER, yusufMalinga$ER,kallisMalinga$ER,uthappaMalinga$ER,
                    gambhirHarbhajan$ER,yusufHarbhajan$ER,kallisHarbhajan$ER,uthappaHarbhajan$ER,
                    gambhirPollard$ER,yusufPollard$ER,kallisPollard$ER,uthappaPollard$ER))
 
 add.constraint(lprec, c(1,1,1,1, 0,0,0,0, 0,0,0,0), "<=",4)
 add.constraint(lprec, c(0,0,0,0,1,1,1,1,0,0,0,0), "<=",4)
 add.constraint(lprec, c(0,0,0,0,0,0,0,0,1,1,1,1), "<=",4)
 add.constraint(lprec, c(1,1,1,1,1,1,1,1,1,1,1,1), "=",10)
 
 add.constraint(lprec, c(1,0,0,0,0,0,0,0,0,0,0,0), ">=",0)
 add.constraint(lprec, c(0,1,0,0,0,0,0,0,0,0,0,0), ">=",1)
 add.constraint(lprec, c(0,0,1,0,0,0,0,0,0,0,0,0), ">=",0)
 add.constraint(lprec, c(0,0,0,1,0,0,0,0,0,0,0,0), ">=",0)
 add.constraint(lprec, c(0,0,0,0,1,0,0,0,0,0,0,0), ">=",0)
 add.constraint(lprec, c(0,0,0,0,0,1,0,0,0,0,0,0), ">=",1)
 add.constraint(lprec, c(0,0,0,0,0,0,1,0,0,0,0,0), ">=",0)
 add.constraint(lprec, c(0,0,0,0,0,0,0,1,0,0,0,0), ">=",1)
 add.constraint(lprec, c(0,0,0,0,0,0,0,0,1,0,0,0), ">=",0)
 add.constraint(lprec, c(0,0,0,0,0,0,0,0,0,1,0,0), ">=",1)
 add.constraint(lprec, c(0,0,0,0,0,0,0,0,0,0,1,0), ">=",0)
 add.constraint(lprec, c(0,0,0,0,0,0,0,0,0,0,0,1), ">=",0)
 
 lprec
## Model name: 
##   a linear program with 12 decision variables and 16 constraints
 b=solve(lprec)
 get.objective(lprec) #  
## [1] 55.57887
 get.variables(lprec) # 
##  [1] 3 1 0 0 0 1 0 1 3 1 0 0
e <- as.data.frame(rbind(c(3,1,0,0,4),c(0, 1, 0,1,2),c(3, 1, 0,0,4)))
names(e) <- c("Gambhir","Yusuf","Kallis","Uthappa","Overs")
rownames(e) <- c("Malinga","Harbhajan","Pollard") 
e

LP Solution: Mumbai Indians can restrict Kolkata Knight Riders to 55.87 in 10 overs
if the overs are bowled as below

##           Gambhir Yusuf Kallis Uthappa Overs
## Malinga         3     1      0       0     4
## Harbhajan       0     1      0       1     2
## Pollard         3     1      0       0     4
#Total overs=10  

8. LP formulation for IPL (Mumbai Indians – Kolkata Knight Riders – Batting lineup)

As I mentioned it is possible to perform a maximation with the same formulation since computeSR<==>computeER

This just flips the problem around and computes the maximum runs that can be scored for the batsman’s Strike rate (this is same as the bowler’s Economy rate) i.e.

gambhirMalinga, yusufMalinga, kallisMalinga, uthappaMalinga is the SR of Gambhir, Yusuf Pathan, Kallis and Uthappa against Malinga
gambhirHarbhajan, yusufHarbhajan, kallisHarbhajan, uthappaHarbhajan is the SR of Gambhir, Yusuf Pathan, Kallis and Uthappa against Harbhajan
gambhirPollard, yusufPollard, kallisPollard, uthappaPollard is the SR of Gambhir, Yusuf Pathan, Kallis and Uthappa against Kieron Pollard.

The constraints are Malinga, Harbhajan and Pollard have 4 overs each and remaining overs to be bowled is 10.

 library("lpSolveAPI")
 lprec <- make.lp(0, 12)
 a=lp.control(lprec, sense="max")
 
 a <-set.objfn(lprec, c(gambhirMalinga$ER, yusufMalinga$ER,kallisMalinga$ER,uthappaMalinga$ER,
                    gambhirHarbhajan$ER,yusufHarbhajan$ER,kallisHarbhajan$ER,uthappaHarbhajan$ER,
                    gambhirPollard$ER,yusufPollard$ER,kallisPollard$ER,uthappaPollard$ER))
 
 
 add.constraint(lprec, c(1,1,1,1, 0,0,0,0, 0,0,0,0), "<=",4)
 add.constraint(lprec, c(0,0,0,0,1,1,1,1,0,0,0,0), "<=",4)
 add.constraint(lprec, c(0,0,0,0,0,0,0,0,1,1,1,1), "<=",4)
 add.constraint(lprec, c(1,1,1,1,1,1,1,1,1,1,1,1), "=",11)
 
 add.constraint(lprec, c(1,0,0,0,0,0,0,0,0,0,0,0), ">=",0)
 add.constraint(lprec, c(0,1,0,0,0,0,0,0,0,0,0,0), ">=",1)
 add.constraint(lprec, c(0,0,1,0,0,0,0,0,0,0,0,0), ">=",0)
 add.constraint(lprec, c(0,0,0,1,0,0,0,0,0,0,0,0), ">=",0)
 add.constraint(lprec, c(0,0,0,0,1,0,0,0,0,0,0,0), ">=",0)
 add.constraint(lprec, c(0,0,0,0,0,1,0,0,0,0,0,0), ">=",1)
 add.constraint(lprec, c(0,0,0,0,0,0,1,0,0,0,0,0), ">=",0)
 add.constraint(lprec, c(0,0,0,0,0,0,0,1,0,0,0,0), ">=",1)
 add.constraint(lprec, c(0,0,0,0,0,0,0,0,1,0,0,0), ">=",0)
 add.constraint(lprec, c(0,0,0,0,0,0,0,0,0,1,0,0), ">=",1)
 add.constraint(lprec, c(0,0,0,0,0,0,0,0,0,0,1,0), ">=",0)
 add.constraint(lprec, c(0,0,0,0,0,0,0,0,0,0,0,1), ">=",0)
 lprec
## Model name: 
##   a linear program with 12 decision variables and 16 constraints
 b=solve(lprec)
 get.objective(lprec) #  
## [1] 94.22649
 get.variables(lprec) # 
##  [1] 0 3 0 0 0 1 0 3 0 1 3 0
e <- as.data.frame(rbind(c(0,3,0,0,3),c(0, 1, 0,3,4),c(0, 1, 3,0,4)))
names(e) <- c("Gambhir","Yusuf","Kallis","Uthappa","Overs")
rownames(e) <- c("Malinga","Harbhajan","Pollard") 
e

LP Solution: Kolkata Knight Riders can score a maximum of 94.22 in 11 overs against Mumbai Indians
if the the number of overs KKR face is as below

##           Gambhir Yusuf Kallis Uthappa Overs
## Malinga         0     3      0       0     3
## Harbhajan       0     1      0       3     4
## Pollard         0     1      3       0     4
#Total overs=11  

Conclusion: It is possible to thus determine the optimum no of overs to give to a specific bowler based on his/her Economy Rate with a particular batsman. Similarly one can determine the maximum runs that can be scored by a batsmen based on their strike rate with bowlers. Cricket like many other games is a game of strategy, skill, talent and some amount of luck. So while the LP formulation can provide some direction,  one must be aware anything could happen in a game of cricket!

Thoughts, comments, suggestions welcome!

Also see
1. Inswinger: yorkr swings into International T20s
2. Working with Node.js and PostgreSQL
3. Simulating the domino effect in Android using Box2D and AndEngine
4. Introducing cricket package yorkr: Part 1- Beaten by sheer pace!
5. Introducing QCSimulator: A 5-qubit quantum computing simulator in R
6. A Cloud medley with IBM Bluemix, Cloudant DB and Node.js

To see all posts see Index of Posts

Analysis of IPL T20 matches with yorkr templates


Introduction

In this post I create RMarkdown templates for end-to-end analysis of IPL T20 matches, that are available on Cricsheet based on my R package yorkr.  With these templates you can convert all IPL data which is in yaml format to R dataframes. Further I create data and the necessary templates for analyzing IPL matches, teams and players. All of these can be accessed at yorkrIPLTemplate.

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

9/Rs 320 and $6.99/Rs448 respectively

The templates are

  1. Template for conversion and setup – IPLT20Template.Rmd
  2. Any IPL match – IPLMatchtemplate.Rmd
  3. IPL matches between 2 nations – IPLMatches2TeamTemplate.Rmd
  4. A IPL nations performance against all other IPL nations – IPLAllMatchesAllOppnTemplate.Rmd
  5. Analysis of IPL batsmen and bowlers of all IPL nations – IPLBatsmanBowlerTemplate.Rmd

Besides the templates the repository also includes the converted data for all IPL matches I downloaded from Cricsheet in Dec 2016. So this data is complete till the 2016 IPL season. You can recreate the files as more matches are added to Cricsheet site in IPL 2017 and future seasons. This post contains all the steps needed for detailed analysis of IPL matches, teams and IPL player. This will also be my reference in future if I decide to analyze IPL in future!

See my earlier posts where I analyze IPL T20
1. yorkr crashes the IPL party ! – Part 1
2. yorkr crashes the IPL party! – Part 2
3. yorkr crashes the IPL party! – Part 3!
4. yorkr crashes the IPL party! – Part 4

There will be 5 folders at the root

  1. IPLdata – Match files as yaml from Cricsheet
  2. IPLMatches – Yaml match files converted to dataframes
  3. IPLMatchesBetween2Teams – All Matches between any 2 IPL teams
  4. allMatchesAllOpposition – An IPL teams’s performance against all other teams
  5. BattingBowlingDetails – Batting and bowling details of all IPL teams
library(yorkr)
library(dplyr)

The first few steps take care of the data setup. This needs to be done before any of the analysis of IPL batsmen, bowlers, any IPL match, matches between any 2 IPL countries or analysis of a teams performance against all other countries

There will be 5 folders at the root

  1. data
  2. IPLMatches
  3. IPLMatchesBetween2Teams
  4. allMatchesAllOpposition
  5. BattingBowlingDetails

The source YAML files will be in IPLData folder

1.Create directory of IPLMatches

Some files may give conversions errors. You could try to debug the problem or just remove it from the IPLdata folder. At most 2-4 file will have conversion problems and I usally remove then from the files to be converted.

Also take a look at my GooglyPlus shiny app which was created after performing the same conversion on the Dec 16 data .

convertAllYaml2RDataframesT20("data","IPLMatches")

2.Save all matches between all combinations of IPL nations

This function will create the set of all matches between each IPL team against every other IPL team. This uses the data that was created in IPLMatches, with the convertAllYaml2RDataframesIPL() function.

setwd("./IPLMatchesBetween2Teams")
saveAllMatchesBetween2IPLTeams("../IPLMatches")

3.Save all matches against all opposition

This will create a consolidated dataframe of all matches played by every IPL playing nation against all other nattions. This also uses the data that was created in IPLMatches, with the convertAllYaml2RDataframesIPL() function.

setwd("../allMatchesAllOpposition")
saveAllMatchesAllOppositionIPLT20("../IPLMatches")

4. Create batting and bowling details for each IPL team

These are the current IPL playing teams. You can add to this vector as newer IPL teams start playing IPL. You will get to know all IPL teams by also look at the directory created above namely allMatchesAllOpposition. This also uses the data that was created in IPLMatches, with the convertAllYaml2RDataframesIPL() function.

setwd("../BattingBowlingDetails")
ipl_teams <- list("Chennai Super Kings","Deccan Chargers", "Delhi Daredevils","Kings XI Punjab", 
              "Kochi Tuskers Kerala","Kolkata Knight Riders","Mumbai Indians","Pune Warriors",
              "Rajasthan Royals","Royal Challengers Bangalore","Sunrisers Hyderabad","Gujarat Lions",
                 "Rising Pune Supergiants")

for(i in seq_along(ipl_teams)){
    print(ipl_teams[i])
    val <- paste(ipl_teams[i],"-details",sep="")
    val <- getTeamBattingDetails(ipl_teams[i],dir="../IPLMatches", save=TRUE)

}

for(i in seq_along(ipl_teams)){
    print(ipl_teams[i])
    val <- paste(ipl_teams[i],"-details",sep="")
    val <- getTeamBowlingDetails(ipl_teams[i],dir="../IPLMatches", save=TRUE)

}

5. Get the list of batsmen for a particular IPL team

The following code is needed for analyzing individual IPL batsmen. In IPL a player could have played in multiple IPL teams.

getBatsmen <- function(df){
    bmen <- df %>% distinct(batsman) 
    bmen <- as.character(bmen$batsman)
    batsmen <- sort(bmen)
}
load("Chennai Super Kings-BattingDetails.RData")
csk_details <- battingDetails
load("Deccan Chargers-BattingDetails.RData")
dc_details <- battingDetails
load("Delhi Daredevils-BattingDetails.RData")
dd_details <- battingDetails
load("Kings XI Punjab-BattingDetails.RData")
kxip_details <- battingDetails
load("Kochi Tuskers Kerala-BattingDetails.RData")
ktk_details <- battingDetails
load("Kolkata Knight Riders-BattingDetails.RData")
kkr_details <- battingDetails
load("Mumbai Indians-BattingDetails.RData")
mi_details <- battingDetails
load("Pune Warriors-BattingDetails.RData")
pw_details <- battingDetails
load("Rajasthan Royals-BattingDetails.RData")
rr_details <- battingDetails
load("Royal Challengers Bangalore-BattingDetails.RData")
rcb_details <- battingDetails
load("Sunrisers Hyderabad-BattingDetails.RData")
sh_details <- battingDetails
load("Gujarat Lions-BattingDetails.RData")
gl_details <- battingDetails
load("Rising Pune Supergiants-BattingDetails.RData")
rps_details <- battingDetails

#Get the batsmen for each IPL team
csk_batsmen <- getBatsmen(csk_details)
dc_batsmen <- getBatsmen(dc_details)
dd_batsmen <- getBatsmen(dd_details)
kxip_batsmen <- getBatsmen(kxip_details)
ktk_batsmen <- getBatsmen(ktk_details)
kkr_batsmen <- getBatsmen(kkr_details)
mi_batsmen <- getBatsmen(mi_details)
pw_batsmen <- getBatsmen(pw_details)
rr_batsmen <- getBatsmen(rr_details)
rcb_batsmen <- getBatsmen(rcb_details)
sh_batsmen <- getBatsmen(sh_details)
gl_batsmen <- getBatsmen(gl_details)
rps_batsmen <- getBatsmen(rps_details)

# Save the dataframes
save(csk_batsmen,file="csk.RData")
save(dc_batsmen, file="dc.RData")
save(dd_batsmen, file="dd.RData")
save(kxip_batsmen, file="kxip.RData")
save(ktk_batsmen, file="ktk.RData")
save(kkr_batsmen, file="kkr.RData")
save(mi_batsmen , file="mi.RData")
save(pw_batsmen, file="pw.RData")
save(rr_batsmen, file="rr.RData")
save(rcb_batsmen, file="rcb.RData")
save(sh_batsmen, file="sh.RData")
save(gl_batsmen, file="gl.RData")
save(rps_batsmen, file="rps.RData")

6. Get the list of bowlers for a particular IPL team

The method below can get the list of bowler names for any IPL team.The following code is needed for analyzing individual IPL bowlers. In IPL a player could have played in multiple IPL teams.

getBowlers <- function(df){
    bwlr <- df %>% distinct(bowler) 
    bwlr <- as.character(bwlr$bowler)
    bowler <- sort(bwlr)
}

load("Chennai Super Kings-BowlingDetails.RData")
csk_details <- bowlingDetails
load("Deccan Chargers-BowlingDetails.RData")
dc_details <- bowlingDetails
load("Delhi Daredevils-BowlingDetails.RData")
dd_details <- bowlingDetails
load("Kings XI Punjab-BowlingDetails.RData")
kxip_details <- bowlingDetails
load("Kochi Tuskers Kerala-BowlingDetails.RData")
ktk_details <- bowlingDetails
load("Kolkata Knight Riders-BowlingDetails.RData")
kkr_details <- bowlingDetails
load("Mumbai Indians-BowlingDetails.RData")
mi_details <- bowlingDetails
load("Pune Warriors-BowlingDetails.RData")
pw_details <- bowlingDetails
load("Rajasthan Royals-BowlingDetails.RData")
rr_details <- bowlingDetails
load("Royal Challengers Bangalore-BowlingDetails.RData")
rcb_details <- bowlingDetails
load("Sunrisers Hyderabad-BowlingDetails.RData")
sh_details <- bowlingDetails
load("Gujarat Lions-BowlingDetails.RData")
gl_details <- bowlingDetails
load("Rising Pune Supergiants-BowlingDetails.RData")
rps_details <- bowlingDetails

# Get the bowlers for each team
csk_bowlers <- getBowlers(csk_details)
dc_bowlers <- getBowlers(dc_details)
dd_bowlers <- getBowlers(dd_details)
kxip_bowlers <- getBowlers(kxip_details)
ktk_bowlers <- getBowlers(ktk_details)
kkr_bowlers <- getBowlers(kkr_details)
mi_bowlers <- getBowlers(mi_details)
pw_bowlers <- getBowlers(pw_details)
rr_bowlers <- getBowlers(rr_details)
rcb_bowlers <- getBowlers(rcb_details)
sh_bowlers <- getBowlers(sh_details)
gl_bowlers <- getBowlers(gl_details)
rps_bowlers <- getBowlers(rps_details)

#Save the dataframes
save(csk_bowlers,file="csk1.RData")
save(dc_bowlers, file="dc1.RData")
save(dd_bowlers, file="dd1.RData")
save(kxip_bowlers, file="kxip1.RData")
save(ktk_bowlers, file="ktk1.RData")
save(kkr_bowlers, file="kkr1.RData")
save(mi_bowlers , file="mi1.RData")
save(pw_bowlers, file="pw1.RData")
save(rr_bowlers, file="rr1.RData")
save(rcb_bowlers, file="rcb1.RData")
save(sh_bowlers, file="sh1.RData")
save(gl_bowlers, file="gl1.RData")
save(rps_bowlers, file="rps1.RData")

Now we are all set

A)  IPL T20 Match Analysis

1 IPL Match Analysis

Load any match data from the ./IPLMatches folder for e.g. Chennai Super Kings-Deccan Chargers-2008-05-06.RData

setwd("./IPLMatches")
load("Chennai Super Kings-Deccan Chargers-2008-05-06.RData")
csk_dc<- overs
#The steps are
load("IPLTeam1-IPLTeam2-Date.Rdata")
IPLTeam1_IPLTeam2 <- overs

All analysis for this match can be done now

2. Scorecard

teamBattingScorecardMatch(IPLTeam1_IPLTeam2,"IPLTeam1")
teamBattingScorecardMatch(IPLTeam1_IPLTeam2,"IPLTeam2")

3.Batting Partnerships

teamBatsmenPartnershipMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2")
teamBatsmenPartnershipMatch(IPLTeam1_IPLTeam2,"IPLTeam2","IPLTeam1")

4. Batsmen vs Bowler Plot

teamBatsmenVsBowlersMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2",plot=TRUE)
teamBatsmenVsBowlersMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2",plot=FALSE)

5. Team bowling scorecard

teamBowlingScorecardMatch(IPLTeam1_IPLTeam2,"IPLTeam1")
teamBowlingScorecardMatch(IPLTeam1_IPLTeam2,"IPLTeam2")

6. Team bowling Wicket kind match

teamBowlingWicketKindMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2")
m <-teamBowlingWicketKindMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2",plot=FALSE)
m

7. Team Bowling Wicket Runs Match

teamBowlingWicketRunsMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2")
m <-teamBowlingWicketRunsMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2",plot=FALSE)
m

8. Team Bowling Wicket Match

m <-teamBowlingWicketMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2",plot=FALSE)
m
teamBowlingWicketMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2")

9. Team Bowler vs Batsmen

teamBowlersVsBatsmenMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2")
m <- teamBowlersVsBatsmenMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2",plot=FALSE)
m

10. Match Worm chart

matchWormGraph(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2")

B)  IPL  Matches between 2  IPL teams

1 IPL Match Analysis

Load any match data from the ./IPLMatches folder for e.g. Chennai Super Kings-Deccan Chargers-2008-05-06.RData

setwd("./IPLMatches")
load("Chennai Super Kings-Deccan Chargers-2008-05-06.RData")
csk_dc<- overs
#The steps are
load("IPLTeam1-IPLTeam2-Date.Rdata")
IPLTeam1_IPLTeam2 <- overs

All analysis for this match can be done now

2. Scorecard

teamBattingScorecardMatch(IPLTeam1_IPLTeam2,"IPLTeam1")
teamBattingScorecardMatch(IPLTeam1_IPLTeam2,"IPLTeam2")

3.Batting Partnerships

teamBatsmenPartnershipMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2")
teamBatsmenPartnershipMatch(IPLTeam1_IPLTeam2,"IPLTeam2","IPLTeam1")

4. Batsmen vs Bowler Plot

teamBatsmenVsBowlersMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2",plot=TRUE)
teamBatsmenVsBowlersMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2",plot=FALSE)

5. Team bowling scorecard

teamBowlingScorecardMatch(IPLTeam1_IPLTeam2,"IPLTeam1")
teamBowlingScorecardMatch(IPLTeam1_IPLTeam2,"IPLTeam2")

6. Team bowling Wicket kind match

teamBowlingWicketKindMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2")
m <-teamBowlingWicketKindMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2",plot=FALSE)
m

7. Team Bowling Wicket Runs Match

teamBowlingWicketRunsMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2")
m <-teamBowlingWicketRunsMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2",plot=FALSE)
m

8. Team Bowling Wicket Match

m <-teamBowlingWicketMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2",plot=FALSE)
m
teamBowlingWicketMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2")

9. Team Bowler vs Batsmen

teamBowlersVsBatsmenMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2")
m <- teamBowlersVsBatsmenMatch(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2",plot=FALSE)
m

10. Match Worm chart

matchWormGraph(IPLTeam1_IPLTeam2,"IPLTeam1","IPLTeam2")

C)  IPL Matches for a team against all other teams

1. IPL Matches for a team against all other teams

Load the data between for a IPL team against all other countries ./allMatchesAllOpposition for e.g all matches of Kolkata Knight Riders

load("allMatchesAllOpposition-Kolkata Knight Riders.RData")
kkr_matches <- matches
IPLTeam="IPLTeam1"
allMatches <- paste("allMatchesAllOposition-",IPLTeam,".RData",sep="")
load(allMatches)
IPLTeam1AllMatches <- matches

2. Team’s batting scorecard all Matches

m <-teamBattingScorecardAllOppnAllMatches(IPLTeam1AllMatches,theTeam="IPLTeam1")
m

3. Batting scorecard of opposing team

m <-teamBattingScorecardAllOppnAllMatches(matches=IPLTeam1AllMatches,theTeam="IPLTeam2")

4. Team batting partnerships

m <- teamBatsmenPartnershipAllOppnAllMatches(IPLTeam1AllMatches,theTeam="IPLTeam1")
m
m <- teamBatsmenPartnershipAllOppnAllMatches(IPLTeam1AllMatches,theTeam='IPLTeam1',report="detailed")
head(m,30)
m <- teamBatsmenPartnershipAllOppnAllMatches(IPLTeam1AllMatches,theTeam='IPLTeam1',report="summary")
m

5. Team batting partnerships plot

teamBatsmenPartnershipAllOppnAllMatchesPlot(IPLTeam1AllMatches,"IPLTeam1",main="IPLTeam1")
teamBatsmenPartnershipAllOppnAllMatchesPlot(IPLTeam1AllMatches,"IPLTeam1",main="IPLTeam2")

6, Team batsmen vs bowlers report

m <-teamBatsmenVsBowlersAllOppnAllMatchesRept(IPLTeam1AllMatches,"IPLTeam1",rank=0)
m
m <-teamBatsmenVsBowlersAllOppnAllMatchesRept(IPLTeam1AllMatches,"IPLTeam1",rank=1,dispRows=30)
m
m <-teamBatsmenVsBowlersAllOppnAllMatchesRept(matches=IPLTeam1AllMatches,theTeam="IPLTeam2",rank=1,dispRows=25)
m

7. Team batsmen vs bowler plot

d <- teamBatsmenVsBowlersAllOppnAllMatchesRept(IPLTeam1AllMatches,"IPLTeam1",rank=1,dispRows=50)
d
teamBatsmenVsBowlersAllOppnAllMatchesPlot(d)
d <- teamBatsmenVsBowlersAllOppnAllMatchesRept(IPLTeam1AllMatches,"IPLTeam1",rank=2,dispRows=50)
teamBatsmenVsBowlersAllOppnAllMatchesPlot(d)

8. Team bowling scorecard

teamBowlingScorecardAllOppnAllMatchesMain(matches=IPLTeam1AllMatches,theTeam="IPLTeam1")
teamBowlingScorecardAllOppnAllMatches(IPLTeam1AllMatches,'IPLTeam2')

9. Team bowler vs batsmen

teamBowlersVsBatsmenAllOppnAllMatchesMain(IPLTeam1AllMatches,theTeam="IPLTeam1",rank=0)
teamBowlersVsBatsmenAllOppnAllMatchesMain(IPLTeam1AllMatches,theTeam="IPLTeam1",rank=2)
teamBowlersVsBatsmenAllOppnAllMatchesRept(matches=IPLTeam1AllMatches,theTeam="IPLTeam1",rank=0)

10. Team Bowler vs bastmen

df <- teamBowlersVsBatsmenAllOppnAllMatchesRept(IPLTeam1AllMatches,theTeam="IPLTeam1",rank=1)
teamBowlersVsBatsmenAllOppnAllMatchesPlot(df,"IPLTeam1","IPLTeam1")

11. Team bowler wicket kind

teamBowlingWicketKindAllOppnAllMatches(IPLTeam1AllMatches,t1="IPLTeam1",t2="All")
teamBowlingWicketKindAllOppnAllMatches(IPLTeam1AllMatches,t1="IPLTeam1",t2="IPLTeam2")

12.

teamBowlingWicketRunsAllOppnAllMatches(IPLTeam1AllMatches,t1="IPLTeam1",t2="All",plot=TRUE)
teamBowlingWicketRunsAllOppnAllMatches(IPLTeam1AllMatches,t1="IPLTeam1",t2="IPLTeam2",plot=TRUE)

1 IPL Batsman setup functions

Get the batsman’s details for a batsman

setwd("../BattingBowlingDetails")
# IPL Team names
IPLTeamNames <- list("Chennai Super Kings","Deccan Chargers", "Delhi Daredevils","Kings Xi Punjab", 
                  "Kochi Tuskers Kerala","Kolkata Knight Riders","Mumbai Indians","Pune Warriors",
                  "Rajasthan Royals","Royal Challengers Bangalore","Sunrisers Hyderabad","Gujarat Lions",
                  "Rising Pune Supergiants")           


# Check and get the team indices of IPL teams in which the batsman has played
getTeamIndex <- function(batsman){
    setwd("./BattingBowlingDetails")
    load("csk.RData")
    load("dc.RData")
    load("dd.RData")
    load("kxip.RData")
    load("ktk.RData")
    load("kkr.RData")
    load("mi.RData")
    load("pw.RData")
    load("rr.RData")
    load("rcb.RData")
    load("sh.RData")
    load("gl.RData")
    load("rps.RData")
    setwd("..")
    getwd()
    print(ls())
    teams_batsmen = list(csk_batsmen,dc_batsmen,dd_batsmen,kxip_batsmen,ktk_batsmen,kkr_batsmen,mi_batsmen,
                         pw_batsmen,rr_batsmen,rcb_batsmen,sh_batsmen,gl_batsmen,rps_batsmen)
    b <- NULL
    for (i in 1:length(teams_batsmen)){
        a <- which(teams_batsmen[[i]] == batsman)

        if(length(a) != 0)
            b <- c(b,i)
    }
    b
}

# Get the list of the IPL team names from the indices passed
getTeams <- function(x){

    l <- NULL
    # Get the teams passed in as indexes
    for (i in seq_along(x)){

        l <- c(l, IPLTeamNames[[x[i]]]) 

    }
    l
}

# Create a consolidated data frame with all teams the IPL batsman has played for
getIPLBatsmanDF <- function(teamNames){
    batsmanDF <- NULL
   # Create a consolidated Data frame of batsman for all IPL teams played
    for (i in seq_along(teamNames)){
       df <- getBatsmanDetails(team=teamNames[i],name=IPLBatsman,dir="./BattingBowlingDetails")
       batsmanDF <- rbind(batsmanDF,df) 

    }
    batsmanDF
}

2. Create a consolidated IPL batsman data frame

# Since an IPL batsman coculd have played in multiple teams we need to determine these teams and
# create a consolidated data frame for the analysis
# For example to check MS Dhoni we need to do the following

IPLBatsman = "MS Dhoni"
#Check and get the team indices of IPL teams in which the batsman has played
i <- getTeamIndex(IPLBatsman)

# Get the team names in which the IPL batsman has played
teamNames <- getTeams(i)
    # Check if file exists in the directory. This check is necessary when moving between matchType


############## Create a consolidated IPL batsman dataframe for analysis
batsmanDF <- getIPLBatsmanDF(teamNames)

3. Runs vs deliveries

# For e.g. batsmanName="MS Dhoni""
#batsmanRunsVsDeliveries(batsmanDF, "MS Dhoni")
batsmanRunsVsDeliveries(batsmanDF,"batsmanName")

4. Batsman 4s & 6s

batsman46 <- select(batsmanDF,batsman,ballsPlayed,fours,sixes,runs)
p1 <- batsmanFoursSixes(batsman46,"batsmanName")

5. Batsman dismissals

batsmanDismissals(batsmanDF,"batsmanName")

6. Runs vs Strike rate

batsmanRunsVsStrikeRate(batsmanDF,"batsmanName")

7. Batsman Moving Average

batsmanMovingAverage(batsmanDF,"batsmanName")

8. Batsman cumulative average

batsmanCumulativeAverageRuns(batsmanDF,"batsmanName")

9. Batsman cumulative strike rate

batsmanCumulativeStrikeRate(batsmanDF,"batsmanName")

10. Batsman runs against oppositions

batsmanRunsAgainstOpposition(batsmanDF,"batsmanName")

11. Batsman runs vs venue

batsmanRunsVenue(batsmanDF,"batsmanName")

12. Batsman runs predict

batsmanRunsPredict(batsmanDF,"batsmanName")

13.Bowler set up functions

setwd("../BattingBowlingDetails")
# IPL Team names
IPLTeamNames <- list("Chennai Super Kings","Deccan Chargers", "Delhi Daredevils","Kings Xi Punjab", 
                  "Kochi Tuskers Kerala","Kolkata Knight Riders","Mumbai Indians","Pune Warriors",
                  "Rajasthan Royals","Royal Challengers Bangalore","Sunrisers Hyderabad","Gujarat Lions",
                  "Rising Pune Supergiants")    



# Get the team indices of IPL teams for which the bowler as played
getTeamIndex_bowler <- function(bowler){
    # Load IPL Bowlers
    setwd("./data")
    load("csk1.RData")
    load("dc1.RData")
    load("dd1.RData")
    load("kxip1.RData")
    load("ktk1.RData")
    load("kkr1.RData")
    load("mi1.RData")
    load("pw1.RData")
    load("rr1.RData")
    load("rcb1.RData")
    load("sh1.RData")
    load("gl1.RData")
    load("rps1.RData")
    setwd("..")
    teams_bowlers = list(csk_bowlers,dc_bowlers,dd_bowlers,kxip_bowlers,ktk_bowlers,kkr_bowlers,mi_bowlers,
                         pw_bowlers,rr_bowlers,rcb_bowlers,sh_bowlers,gl_bowlers,rps_bowlers)
    b <- NULL
    for (i in 1:length(teams_bowlers)){
        a <- which(teams_bowlers[[i]] == bowler)
        if(length(a) != 0){
            b <- c(b,i)
        }
    }
    b
}


# Get the list of the IPL team names from the indices passed
getTeams <- function(x){

    l <- NULL
    # Get the teams passed in as indexes
    for (i in seq_along(x)){

        l <- c(l, IPLTeamNames[[x[i]]]) 

    }
    l
}

# Get the team names
teamNames <- getTeams(i)

getIPLBowlerDF <- function(teamNames){
    bowlerDF <- NULL

    # Create a consolidated Data frame of batsman for all IPL teams played
    for (i in seq_along(teamNames)){
          df <- getBowlerWicketDetails(team=teamNames[i],name=IPLBowler,dir="./BattingBowlingDetails")
          bowlerDF <- rbind(bowlerDF,df) 

    }
    bowlerDF
}

14. Get the consolidated data frame for an IPL bowler

# Since an IPL bowler could have played in multiple teams we need to determine these teams and
# create a consolidated data frame for the analysis
# For example to check R Ashwin we need to do the following

IPLBowler = "R Ashwin"
#Check and get the team indices of IPL teams in which the batsman has played
i <- getTeamIndex(IPLBowler)

# Get the team names in which the IPL batsman has played
teamNames <- getTeams(i)
    # Check if file exists in the directory. This check is necessary when moving between matchType


############## Create a consolidated IPL batsman dataframe for analysis
bowlerDF <- getIPLBowlerDF(teamNames)

15. Bowler Mean Economy rate

# For e.g. to get the details of R Ashwin do
#bowlerMeanEconomyRate(bowlerDF,"R Ashwin")
bowlerMeanEconomyRate(bowlerDF,"bowlerName")

16. Bowler mean runs conceded

bowlerMeanRunsConceded(bowlerDF,"bowlerName")

17. Bowler Moving Average

bowlerMovingAverage(bowlerDF,"bowlerName")

18. Bowler cumulative average wickets

bowlerCumulativeAvgWickets(bowlerDF,"bowlerName")

19. Bowler cumulative Economy Rate (ER)

bowlerCumulativeAvgEconRate(bowlerDF,"bowlerName")

20. Bowler wicket plot

bowlerWicketPlot(bowlerDF,"bowlerName")

21. Bowler wicket against opposition

bowlerWicketsAgainstOpposition(bowlerDF,"bowlerName")

22. Bowler wicket at cricket grounds

bowlerWicketsVenue(bowlerDF,"bowlerName")

23. Predict number of deliveries to wickets

setwd("./IPLMatches")
bowlerDF1 <- getDeliveryWickets(team="IPLTeam1",dir=".",name="bowlerName",save=FALSE)
bowlerWktsPredict(bowlerDF1,"bowlerName")

You may like
1. Using Linear Programming (LP) for optimizing bowling change or batting lineup in T20 cricket
2. Neural Networks: The mechanics of backpropagation
3. More book, more cricket! 2nd edition of my books now on Amazon
4. Spicing up a IBM Bluemix cloud app with MongoDB and NodeExpress
5. Introducing cricket package yorkr:Part 4-In the block hole!

GooglyPlus: yorkr analyzes IPL players, teams, matches with plots and tables


In this post I introduce my new Shiny app,“GooglyPlus”, which is a  more evolved version of my earlier Shiny app “Googly”. My R package ‘yorkr’,  on which both these Shiny apps are based, has the ability to output either a dataframe or plot, depending on a parameter plot=TRUE or FALSE. My initial version of the app only included plots, and did not exercise the yorkr package fully. Moreover, I am certain, there may be a set of cricket aficionados who would prefer, numbers to charts. Hence I have created this enhanced version of the Googly app and appropriately renamed it as GooglyPlus. GooglyPlus is based on the yorkr package which uses data from Cricsheet. The app is based on IPL data from  all IPL matches from 2008 up to 2016. Feel free to clone/fork or download the code from Github at GooglyPlus.

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

 

Click  GooglyPlus to access the Shiny app!

The changes for GooglyPlus over the earlier Googly app is only in the following 3 tab panels

  • IPL match
  • Head to head
  • Overall Performance

The analysis of IPL batsman and IPL bowler tabs are unchanged. These charts are as they were before.

The changes are only in  tabs i) IPL match ii) Head to head and  iii) Overall Performance. New functionality has been added and existing functions now have the dual option of either displaying a plot or a table.

The changes are

A) IPL Match
The following additions/enhancements have been done

-Match Batting Scorecard – Table
-Batting Partnerships – Plot, Table (New)
-Batsmen vs Bowlers – Plot, Table(New)
-Match Bowling Scorecard   – Table (New)
-Bowling Wicket Kind – Plot, Table (New)
-Bowling Wicket Runs – Plot, Table (New)
-Bowling Wicket Match – Plot, Table (New)
-Bowler vs Batsmen – Plot, Table (New)
-Match Worm Graph – Plot

B) Head to head
The following functions have been added/enhanced

-Team Batsmen Batting Partnerships All Matches – Plot, Table {Summary (New) and Detailed (New)}
-Team Batting Scorecard All Matches – Table (New)
-Team Batsmen vs Bowlers all Matches – Plot, Table (New)
-Team Wickets Opposition All Matches – Plot, Table (New)
-Team Bowling Scorecard All Matches – Table (New)
-Team Bowler vs Batsmen All Matches – Plot, Table (New)
-Team Bowlers Wicket Kind All Matches – Plot, Table (New)
-Team Bowler Wicket Runs All Matches – Plot, Table (New)
-Win Loss All Matches – Plot

C) Overall Performance
The following additions/enhancements have been done in this tab

-Team Batsmen Partnerships Overall – Plot, Table {Summary (New) and Detailed (New)}
-Team Batting Scorecard Overall –Table (New)
-Team Batsmen vs Bowlers Overall – Plot, Table (New)
-Team Bowler vs Batsmen Overall – Plot, Table (New)
-Team Bowling Scorecard Overall – Table (New)
-Team Bowler Wicket Kind Overall – Plot, Table (New)

Included below are some random charts and tables. Feel free to explore the Shiny app further

1) IPL Match
a) Match Batting Scorecard (Table only)
This is the batting score card for the Chennai Super Kings & Deccan Chargers 2011-05-11

untitled

b)  Match batting partnerships (Plot)
Delhi Daredevils vs Kings XI Punjab – 2011-04-23

untitled

c) Match batting partnerships (Table)
The same batting partnership  Delhi Daredevils vs Kings XI Punjab – 2011-04-23 as a table

untitled

d) Batsmen vs Bowlers (Plot)
Kolkata Knight Riders vs Mumbai Indians 2010-04-19

Untitled.png

e)  Match Bowling Scorecard (Table only)
untitled

B) Head to head

a) Team Batsmen Partnership (Plot)
Deccan Chargers vs Kolkata Knight Riders all matches

untitled

b)  Team Batsmen Partnership (Summary – Table)
In the following tables it can be seen that MS Dhoni has performed better that SK Raina  CSK against DD matches, whereas SK Raina performs better than Dhoni in CSK vs  KKR matches

i) Chennai Super Kings vs Delhi Daredevils (Summary – Table)

untitled

ii) Chennai Super Kings vs Kolkata Knight Riders (Summary – Table)
untitled

iii) Rising Pune Supergiants vs Gujarat Lions (Detailed – Table)
This table provides the detailed partnership for RPS vs GL all matches

untitled

c) Team Bowling Scorecard (Table only)
This table gives the bowling scorecard of Pune Warriors vs Deccan Chargers in all matches

untitled

C) Overall performances
a) Batting Scorecard All Matches  (Table only)

This is the batting scorecard of Royal Challengers Bangalore. The top 3 batsmen are V Kohli, C Gayle and AB Devilliers in that order

untitled

b) Batsman vs Bowlers all Matches (Plot)
This gives the performance of Mumbai Indian’s batsman of Rank=1, which is Rohit Sharma, against bowlers of all other teams

untitled

c)  Batsman vs Bowlers all Matches (Table)
The above plot as a table. It can be seen that Rohit Sharma has scored maximum runs against M Morkel, then Shakib Al Hasan and then UT Yadav.

untitled

d) Bowling scorecard (Table only)
The table below gives the bowling scorecard of CSK. R Ashwin leads with a tally of 98 wickets followed by DJ Bravo who has 88 wickets and then JA Morkel who has 83 wickets in all matches against all teams

Untitled.png

This is just a random selection of functions. Do play around with the app and checkout how the different IPL batsmen, bowlers and teams stack against each other. Do read my earlier post Googly: An interactive app for analyzing IPL players, matches and teams using R package yorkr  for more details about the app and other functions available.

Click GooglyPlus to access the Shiny app!

You can clone/fork/download the code from Github at GooglyPlus

Hope you have fun playing around with the Shiny app!

Note: In the tabs, for some of the functions, not all controls  are required. It is possible to enable the controls selectively but this has not been done in this current version. I may make the changes some time in the future.

Take a look at my other Shiny apps
a.Revisiting crimes against women in India
b. Natural language processing: What would Shakespeare say?

Check out some of my other posts
1. Analyzing World Bank data with WDI, googleVis Motion Charts
2. Video presentation on Machine Learning, Data Science, NLP and Big Data – Part 1
3. Singularity
4. Design principles of scalable, distributed systems
5. Simulating an Edge shape in Android
6. Dabbling with Wiener filter in OpenCV

To see all posts click Index of Posts

Googly: An interactive app for analyzing IPL players, matches and teams using R package yorkr


Presenting ‘Googly’, a cool Shiny app that I developed over the last couple of days. This interactive Shiny app was on my mind for quite some time, and I finally got down to implementing it. The Googly Shiny app is based on my R package ‘yorkr’ which is now available in CRAN. The R package and hence this Shiny app is based on data from Cricsheet.

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

Googly is based on R package yorkr, and uses the data of all IPL matches from 2008 up to 2016, available on Cricsheet.

Googly can do detailed analyses of a) Individual IPL batsman b) Individual IPL bowler c) Any IPL match d) Head to head confrontation between 2 IPL teams e) All matches of an IPL team against all other teams.

With respect to the individual IPL batsman and bowler performance, I was in a bit of a ‘bind’ literally (pun unintended), as any IPL player could have played in more than 1 IPL team. Fortunately ‘rbind’ came to my rescue. I just get all the batsman’s/bowler’s performance in each IPL team, and then consolidate it into a single large dataframe to do the analyses of.

The Shiny app can be accessed at Googly

The code for Googly is available at Github. Feel free to clone/download/fork  the code from Googly

Check out my 2 books on cricket, a) Cricket analytics with cricketr b) Beaten by sheer pace – Cricket analytics with yorkr, now available in both paperback & kindle versions on Amazon!!! Pick up your copies today!

Also see my post GooglyPlus: yorkr analyzes IPL players, teams, matches with plots and tables

Based on the 5 detailed analysis domains there are 5 tabs

IPL Batsman: This tab can be used to perform analysis of all IPL batsman. If a batsman has played in more than 1 team, then the overall performance is considered. There are 10 functions for the IPL Batsman. They are shown below

  1. Batsman Runs vs. Deliveries
  2. Batsman’s Fours & Sixes
  3. Dismissals of batsman
  4. Batsman’s Runs vs Strike Rate
  5. Batsman’s Moving Average
  6. Batsman’s Cumulative Average Run
  7. Batsman’s Cumulative Strike Rate
  8. Batsman’s Runs against Opposition
  9. Batsman’s Runs at Venue
  10. Predict Runs of batsman

IPL Bowler: This tab can be used to analyze individual IPL bowlers. The functions handle IPL bowlers who have played in more than 1 IPL team.

  1. Mean Economy Rate of bowler
  2. Mean runs conceded by bowler
  3. Bowler’s Moving Average
  4. Bowler’s Cumulative Avg. Wickets
  5. Bowler’s Cumulative Avg. Economy Rate
  6. Bowler’s Wicket Plot
  7. Bowler’s Wickets against opposition
  8. Bowler’s Wickets at Venues
  9. Bowler’s wickets prediction

IPL match: This tab can be used for analyzing individual IPL matches. The available functions are

  1. Batting Partnerships
  2. Batsmen vs Bowlers
  3. Bowling Wicket Kind
  4. Bowling Wicket Runs
  5. Bowling Wicket Match
  6. Bowler vs Batsmen
  7. Match Worm Graph

Head to head : This tab can be used for analyzing head-to-head confrontations, between any 2 IPL teams for e.g. all matches between Chennai Super Kings vs. Deccan Chargers or Kolkata Knight Riders vs. Delhi Daredevils. The available functions are

  1. Team Batsmen Batting Partnerships All Matches
  2. Team Batsmen vs Bowlers all Matches
  3. Team Wickets Opposition All Matches
  4. Team Bowler vs Batsmen All Matches
  5. Team Bowlers Wicket Kind All Matches
  6. Team Bowler Wicket Runs All Matches
  7. Win Loss All Matches

Overall performance : this tab can be used analyze the overall performance of any IPL team. For this analysis all matches played by this team is considered. The available functions are

  1. Team Batsmen Partnerships Overall
  2. Team Batsmen vs Bowlers Overall
  3. Team Bowler vs Batsmen Overall
  4. Team Bowler Wicket Kind Overall

Below I include a random set of charts that are generated in each of the 5 tabs

A. IPL Batsman
a. A Symonds : Runs vs Deliveries
untitled

b. AB Devilliers – Cumulative Strike Rate
untitled

c.  Gautam Gambhir – Runs at venues
untitled

d. CH Gayle – Predict runs 
untitled

B. IPL Bowler
a. Ashish Nehra – Cumulative Average Wickets
untitled

b.  DJ Bravo – Moving Average of wickets
untitled

c. R Ashwin – Mean Economy rate vs Overs
untitled

C.IPL Match
a. Chennai Super Kings vs Deccan Chargers   (2008 -05-06) – Batsmen Partnerships

Note: You can choose either team in the match from the drop down ‘Choose team’

untitled

b. Kolkata Knight Riders vs Delhi Daredevils (2013-04-02) – Bowling wicket runs
untitled

c. Mumbai Indians vs Kings XI Punjab (2010-03-30) – Match worm graph
untitled

D. Head to head confrontation
a. Rising Pune Supergiants vs Mumbai Indians in all matches – Team batsmen partnerships

Note: You can choose the partnership of either team in the drop down ‘Choose team’
untitled

b.  Gujarat Lions – Royal Challengers Bangalore all matches – Bowlers performance against batsmen
untitled

E. Overall Performance
a.  Royal Challengers Bangalore overall performance – Batsman Partnership (Rank=1)
This is Virat Kohli for RCB. Try out other ranks
untitled

b.  Rajashthan Royals overall Performance – Bowler vs batsman (Rank =2)
This is Vinay Kumar.
untitled

The Shiny app Googly can be accessed at Googly. Feel free to clone/fork the code from Github at Googly

For details on my R package yorkr, please see my blog Giga thoughts. There are more than 15 posts detailing the functions and their usage.

Do bowl a Googly!!!

You may like my other Shiny apps

Also see my other posts

  1. Introducing QCSimulator: A 5-qubit quantum computing simulator in R
  2. Deblurring with OpenCV: Weiner filter reloaded
  3. Rock N’ Roll with Bluemix, Cloudant & NodeExpress
  4. Introducing cricket package yorkr: Part 1- Beaten by sheer pace!
  5. Fun simulation of a Chain in Android
  6. Beaten by sheer pace! Cricket analytics with yorkr in paperback and Kindle versions
  7. Introducing cricketr! : An R package to analyze performances of cricketers
  8. Cricket analytics with cricketr!!!

For more posts see Index of posts

yorkr ranks IPL Players post 2016 season


Here is a short post which ranks IPL batsmen and bowlers post the 2016 IPL season. These are based on match data from Cricsheet. I had already ranked IPL players in my post yorkr ranks IPL batsmen and bowlers, but that was mid IPL 2016 season. This post will be final ranking post 2016 season

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 has also been published in RPubs RankIPLPlayers2016. You can download this as a pdf file at RankIPLPlayers2016.pdf.

You can take a look at the code at rankIPLPlayers2016

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

rm(list=ls())
library(yorkr)
library(dplyr)
source('C:/software/cricket-package/cricsheet/ipl2016/final/R/rankIPLBatsmen.R', encoding = 'UTF-8')
source('C:/software/cricket-package/cricsheet/ipl2016/final/R/rankIPLBowlers.R', encoding = 'UTF-8')

Rank IPL batsmen post 2016

Chris Gayle, Shaun Marsh & David Warner are top 3 IPL batsmen. Gayle towers over everybody, with an 38.28 Mean Runs, and a Mean Strike Rate of 138.85. Virat Kohli comes in 4th, with 34.52 as his Average Runs per innings, and a Mean Strike Rate of 117.51

iplBatsmanRank <- rankIPLBatsmen()
as.data.frame(iplBatsmanRank[1:30,])
##             batsman matches meanRuns    meanSR
## 1          CH Gayle      92 38.28261 138.85120
## 2          SE Marsh      60 36.40000 118.97783
## 3         DA Warner     104 34.51923 124.88798
## 4           V Kohli     136 31.77941 117.51000
## 5         AM Rahane      89 31.46067 104.62989
## 6    AB de Villiers     109 29.93578 136.48945
## 7      SR Tendulkar      78 29.62821 108.58962
## 8         G Gambhir     133 28.94737 109.61263
## 9         RG Sharma     140 28.68571 117.79057
## 10         SK Raina     143 28.41259 121.55713
## 11        SR Watson      90 28.21111 125.80122
## 12         S Dhawan     110 28.09091 111.97282
## 13         R Dravid      79 27.87342 109.14544
## 14         DR Smith      76 27.55263 120.22329
## 15        JP Duminy      70 27.28571 122.99243
## 16      BB McCullum      94 26.86170 118.55606
## 17        JH Kallis      97 26.83505  95.47866
## 18         V Sehwag     105 26.26667 137.11562
## 19       RV Uthappa     132 26.18182 123.16326
## 20     AC Gilchrist      81 25.77778 122.69074
## 21          M Vijay      99 25.69697 106.02010
## 22    KC Sangakkara      70 25.67143 112.97529
## 23         MS Dhoni     131 25.14504 131.62206
## 24        DA Miller      60 24.76667 133.80983
## 25        AT Rayudu      99 23.35354 121.59313
## 26 DPMD Jayawardene      80 23.05000 114.54712
## 27     Yuvraj Singh     103 22.46602 118.15000
## 28        DJ Hussey      63 22.26984        NA
## 29        YK Pathan     121 22.25620 132.58793
## 30      S Badrinath      66 22.22727 114.97061

Rank IPL bowlers

The top 3 IPL T20 bowlers are SL Malinga, DJ Bravo and SP Narine

Don’t get hung up on the decimals in the average wickets for the bowlers. All it implies is that if 2 bowlers have average wickets of 1.0 and 1.5, it implies that in 2 matches the 1st bowler will take 2 wickets and the 2nd bowler will take 3 wickets.

setwd("C:/software/cricket-package/cricsheet/ipl2016/details")
iplBowlersRank <- rankIPLBowlers()
as.data.frame(iplBowlersRank[1:30,])
##             bowler matches meanWickets   meanER
## 1       SL Malinga      96    1.645833 6.545208
## 2         DJ Bravo      58    1.517241 7.929310
## 3        SP Narine      65    1.492308 6.155077
## 4          B Kumar      45    1.422222 7.355556
## 5        YS Chahal      41    1.414634 8.057073
## 6         M Morkel      37    1.405405 7.626216
## 7        IK Pathan      40    1.400000 7.579250
## 8         RP Singh      42    1.357143 7.966429
## 9         MM Patel      31    1.354839 7.282581
## 10   R Vinay Kumar      63    1.317460 8.342540
## 11  Sandeep Sharma      38    1.315789 7.697368
## 12       MM Sharma      46    1.304348 7.740652
## 13         P Awana      33    1.303030 8.325758
## 14        MM Patel      30    1.300000 7.569667
## 15          Z Khan      41    1.292683 7.735854
## 16         PP Ojha      53    1.245283 7.268679
## 17     JP Faulkner      40    1.225000 8.502250
## 18 Shakib Al Hasan      41    1.170732 7.103659
## 19     DS Kulkarni      32    1.156250 8.372188
## 20        UT Yadav      46    1.152174 8.394783
## 21        A Kumble      41    1.146341 6.567073
## 22       JA Morkel      73    1.136986 8.131370
## 23        SK Warne      53    1.132075 7.277170
## 24        A Mishra      55    1.127273 7.319455
## 25        UT Yadav      33    1.090909 8.853636
## 26        L Balaji      34    1.088235 7.186176
## 27       PP Chawla      35    1.085714 8.162000
## 28        R Ashwin      92    1.065217 6.812391
## 29  M Muralitharan      39    1.051282 6.470256
## 30 Harbhajan Singh     120    1.050000 7.134833

yorkr ranks IPL batsmen and bowlers


Here is a short post which ranks IPL batsmen and bowlers. These are based on match data from Cricsheet. Ranking batsmen and bowlers in IPL is more challenging as the players can belong to different teams in different years. Hence I create a combined data frame of the batsmen and bowlers regardless of their IPL teams and calculate a) average runs and average strike rate for batsmen and c) average wickets and d) average economy rate for bowlers.

I will be doing this ranking for T20 and ODI batting and bowling performances shortly.

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 has also been published in RPubs RankIPLPlayers. You can download this as a pdf file at RankIPLPlayers.pdf.

You can take a look at the code at rankIPLPlayers (should be available in yorkr_0.0.5)

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

The results are slightly surprising

rm(list=ls())
library(yorkr)
library(dplyr)
setwd("C:/software/cricket-package/cricsheet/cleanup/IPL/rank")
source("rankIPLBatsmen.R")
source("rankIPLBowlers.R")

Rank IPL batsmen

Chris Gayle, MEK Hussey and Shane Watson are top 3 IPL batsmen. Gayle towers over the others in mean runs and mean strike rate. Surprisingly Ajinkya Rahane is the top Indian T20 batsman, if we leave out Sachin Tendulkar (who tops India yet again!). The other top IPL T20 batsmen are Raina, Gambhir, Rohit Sharma in that order. Virat Kohli comes a distant 14th.

iplBatsmanRank <- rankIPLBatsmen()
as.data.frame(iplBatsmanRank[1:30,])
##             batsman matches meanRuns    meanSR
## 1          CH Gayle     128 40.00781 144.92188
## 2        MEK Hussey      64 33.57812 107.23500
## 3         SR Watson      75 31.46667 129.97733
## 4      SR Tendulkar     127 29.74803 108.86622
## 5         AM Rahane      77 29.14286 101.40065
## 6         DA Warner     134 29.10448 118.38313
## 7         JP Duminy      94 28.77660 124.61702
## 8          SK Raina     128 28.62500 122.12656
## 9         G Gambhir     210 28.13810 108.78090
## 10        RG Sharma     181 28.07182 118.57801
## 11         DR Smith      78 27.82051 119.64462
## 12      BB McCullum      98 27.81633 114.91255
## 13         S Dhawan     109 27.74312 112.21000
## 14          V Kohli     188 27.56915 113.81261
## 15   AB de Villiers     150 27.46000 136.70860
## 16         R Dravid     104 27.02885 107.78923
## 17        JH Kallis     167 26.54491  94.65641
## 18         V Sehwag     174 26.39655 140.29011
## 19       RV Uthappa     166 26.27711 120.48506
## 20       SC Ganguly      86 25.98837  96.39849
## 21     AC Gilchrist      81 25.77778 122.69074
## 22    KC Sangakkara      70 25.67143 112.97529
## 23         MS Dhoni     119 25.29412 130.99832
## 24       TM Dilshan      82 24.13415 101.12634
## 25          M Vijay      96 23.92708 102.01771
## 26        AT Rayudu     146 23.63014 117.91000
## 27 DPMD Jayawardene     109 22.95413 110.73862
## 28        MK Pandey     105 22.71429        NA
## 29     Yuvraj Singh     112 22.48214 114.51018
## 30      S Badrinath      66 22.22727 114.97061

Rank IPL bowlers

The top 3 IPL T20 bowlers are SL Malinga,SP Narine and DJ Bravo.

Don’t get hung up on the decimals in the average wickets for the bowlers. All it implies is that if 2 bowlers have average wickets of 1.0 and 1.5, it implies that in 2 matches the 1st bowler will take 2 wickets and the 2nd bowler will take 3 wickets.

iplBowlersRank <- rankIPLBowlers()
as.data.frame(iplBowlersRank[1:30,])
##             bowler matches meanWickets   meanER
## 1       SL Malinga      96    1.645833 6.545208
## 2        SP Narine      54    1.555556 5.967593
## 3         DJ Bravo      58    1.517241 7.929310
## 4         M Morkel      37    1.405405 7.626216
## 5        IK Pathan      40    1.400000 7.579250
## 6         RP Singh      42    1.357143 7.966429
## 7         MM Patel      31    1.354839 7.282581
## 8  Shakib Al Hasan      32    1.343750 6.911250
## 9    R Vinay Kumar      63    1.317460 8.342540
## 10       MM Sharma      46    1.304348 7.740652
## 11         P Awana      33    1.303030 8.325758
## 12        MM Patel      30    1.300000 7.569667
## 13          Z Khan      41    1.292683 7.735854
## 14        A Mishra      43    1.255814 7.226512
## 15         PP Ojha      53    1.245283 7.268679
## 16     JP Faulkner      40    1.225000 8.502250
## 17     DS Kulkarni      32    1.156250 8.372188
## 18        UT Yadav      46    1.152174 8.394783
## 19        A Kumble      41    1.146341 6.567073
## 20       JA Morkel      73    1.136986 8.131370
## 21        SK Warne      53    1.132075 7.277170
## 22 Harbhajan Singh     107    1.102804 7.014953
## 23        L Balaji      34    1.088235 7.186176
## 24        R Ashwin      92    1.065217 6.812391
## 25        AR Patel      31    1.064516 7.137097
## 26  M Muralitharan      39    1.051282 6.470256
## 27         P Kumar      36    1.027778 8.148056
## 28       PP Chawla      85    1.023529 8.017765
## 29       SR Watson      67    1.014925 7.695224
## 30        DJ Bravo      30    1.000000 7.966333

Conclusion: The results are somewhat surprising. The ranking was based on data from Cricsheet. The data in this site are available from 2008-2015. I hope to do this ranking for T20 and ODIs shortly

Watch this space!

  1. Introducing cricket package yorkr-Part1:Beaten by sheer pace!.
  2. yorkr pads up for the Twenty20s: Part 1- Analyzing team“s match performance.
  3. yorkr crashes the IPL party !Part 1
  4. Introducing cricketr! : An R package to analyze performances of cricketers
  5. Cricket analytics with cricketr in paperback and Kindle versions

yorkr crashes the IPL party! – Part 4


Introduction

I’ve missed more than 9000 shots in my career. I’ve lost almost 300 games. 26 times, I’ve been trusted to take the game winning shot and missed. I’ve failed over and over and over again in my life. And that is why I succeed.

                      Michael Jordan

Success is where preparation and opportunity meet.

                      Bobby Unser

It is not whether you get knocked down. It is whether you get up.

                      Vince Lombardi

Make sure your worst enemy doesn’t live between your own two ears.

                      Laird Hamilton

This post should be the last post for “yorkr crashes the IPL party!”. In fact it is final post for the whole ‘yorkr’ series. I have now covered the use of yorkr for ODIs, Twenty20s and IPL T20 formats. I will not be including functionality in yorkr to handle Test cricket from Cricsheet. I would recommend that you use my R package cricketr. Please see my post Introducing cricketr! : An R package to analyze performances of cricketers

In this last post on IPL T20 I look at the top individual batting and bowling performances in the IPL Twenty20s. Also please take a look at my 3 earlier post on yorkr’s handling of IPL Twenty20 matches

  1. yorkr crashes the IPL party ! – Part 1
  2. yorkr crashes the IPL party ! – Part 2
  3. yorkr crashes the IPL party ! – Part 3

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 has also been published at RPubs IPLT20-Part4 and can also be downloaded as a PDF document from IPLT20-Part4.pdf.

You can clone/fork the code for the package yorkr from Github at yorkr-package

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

The list of Class 4 functions are shown below.The Twenty20 features will be available from yorkr_0.0.4

Batsman functions

  1. batsmanRunsVsDeliveries
  2. batsmanFoursSixes
  3. batsmanDismissals
  4. batsmanRunsVsStrikeRate
  5. batsmanMovingAverage
  6. batsmanCumulativeAverageRuns
  7. batsmanCumulativeStrikeRate
  8. batsmanRunsAgainstOpposition
  9. batsmanRunsVenue
  10. batsmanRunsPredict

Bowler functions

  1. bowlerMeanEconomyRate
  2. bowlerMeanRunsConceded
  3. bowlerMovingAverage
  4. bowlerCumulativeAvgWickets
  5. bowlerCumulativeAvgEconRate
  6. bowlerWicketPlot
  7. bowlerWicketsAgainstOpposition
  8. bowlerWicketsVenue
  9. bowlerWktsPredict
library(yorkr)
library(gridExtra)
library(rpart.plot)
library(dplyr)
library(ggplot2)
rm(list=ls())

A. Batsman functions

1. Get IPL Team Batting details

The function below gets the overall IPL team batting details based on the RData file available in IPL T20 matches. This is currently also available in Github at [IPL-T20-matches] (https://github.com/tvganesh/yorkrData/tree/master/IPL/IPL-T20-matches). The batting details of the IPL team in each match is created and a huge data frame is created by rbinding the individual dataframes. This can be saved as a RData file

setwd("C:/software/cricket-package/york-test/yorkrData/IPL/IPL-T20-matches")
csk_details <- getTeamBattingDetails("Chennai Super Kings",dir=".", save=TRUE)
dd_details <- getTeamBattingDetails("Delhi Daredevils",dir=".",save=TRUE)
kkr_details <- getTeamBattingDetails("Kolkata Knight Riders",dir=".",save=TRUE)
mi_details <- getTeamBattingDetails("Mumbai Indians",dir=".",save=TRUE)
rcb_details <- getTeamBattingDetails("Royal Challengers Bangalore",dir=".",save=TRUE)

2. Get IPL batsman details

This function is used to get the individual IPL T20 batting record for a the specified batsman of the team as in the functions below. For analyzing the batting performances I have chosen the top IPL T20 batsmen from the teams. This was based to a large extent on batting scorecard functions from yorkr crashes the IPL party!:Part 3 The top IPL batsmen chosen are the ones below

  1. Suresh Raina (CSK)
  2. MS Dhoni (CSK)
  3. Virendar Sehwag (DD)
  4. Rohit Sharma (MI)
  5. Gautham Gambhir (KKR)
  6. Virat Kohli (RCB)
setwd("C:/software/cricket-package/cricsheet/cleanup/IPL/part4")
raina <- getBatsmanDetails(team="Chennai Super Kings",name="SK Raina",dir=".")
## [1] "./Chennai Super Kings-BattingDetails.RData"
dhoni <- getBatsmanDetails(team="Chennai Super Kings",name="MS Dhoni")
## [1] "./Chennai Super Kings-BattingDetails.RData"
sehwag <-  getBatsmanDetails(team="Delhi Daredevils",name="V Sehwag",dir=".")
## [1] "./Delhi Daredevils-BattingDetails.RData"
gambhir <-  getBatsmanDetails(team="Kolkata Knight Riders",name="G Gambhir",dir=".")
## [1] "./Kolkata Knight Riders-BattingDetails.RData"
rsharma <-  getBatsmanDetails(team="Mumbai Indians",name="RG Sharma",dir=".")
## [1] "./Mumbai Indians-BattingDetails.RData"
kohli <-  getBatsmanDetails(team="Royal Challengers Bangalore",name="V Kohli",dir=".")
## [1] "./Royal Challengers Bangalore-BattingDetails.RData"

3. Runs versus deliveries (in IPL matches)

Sehwag has a superb strike rate. It can be seen that Sehwag averages around 80 runs for around 40 deliveries followed by Rohit Sharma. Raina and Dhoni average around 60 runs

p1 <-batsmanRunsVsDeliveries(raina, "SK Raina")
p2 <-batsmanRunsVsDeliveries(dhoni,"MS Dhoni")
p3 <-batsmanRunsVsDeliveries(sehwag,"V Sehwag")
p4 <-batsmanRunsVsDeliveries(gambhir,"G Gambhir")
p5 <-batsmanRunsVsDeliveries(rsharma,"RG Sharma")
p6 <-batsmanRunsVsDeliveries(kohli,"V Kohli")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

runsVsDeliveries-1

4. Batsman Total runs, Fours and Sixes (in IPL matches)

Dhoni leads in the runs made from sixes in comparison to the others

raina46 <- select(raina,batsman,ballsPlayed,fours,sixes,runs)
p1 <-batsmanFoursSixes(raina46, "SK Raina")
dhoni46 <- select(dhoni,batsman,ballsPlayed,fours,sixes,runs)
p2 <-batsmanFoursSixes(dhoni46,"MS Dhoni")
sehwag46 <- select(sehwag,batsman,ballsPlayed,fours,sixes,runs)
p3 <-batsmanFoursSixes(sehwag46,"V Sehwag")
gambhir46 <- select(gambhir,batsman,ballsPlayed,fours,sixes,runs)
p4 <-batsmanFoursSixes(gambhir46,"G Gambhir")
rsharma46 <- select(rsharma,batsman,ballsPlayed,fours,sixes,runs)
p5 <-batsmanFoursSixes(rsharma46,"RG Sharma")
kohli46 <- select(kohli,batsman,ballsPlayed,fours,sixes,runs)
p6 <-batsmanFoursSixes(kohli46,"V Kohli")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

foursSixes-1

5. Batsman dismissals (in IPL matches)

The type of dismissal for each batsman is shown below

p1 <-batsmanDismissals(raina, "SK Raina")
p2 <-batsmanDismissals(dhoni,"MS Dhoni")
p3 <-batsmanDismissals(sehwag,"V Sehwag")
p4 <-batsmanDismissals(gambhir,"G Gambhir")
p5 <-batsmanDismissals(rsharma,"RG Sharma")
p6 <-batsmanDismissals(kohli,"V Kohli")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

dismissal-1

6. Runs versus Strike Rate (in IPL matches)

Raina, Dhoni and Kohli have an increasing strike rate with more runs scored

p1 <-batsmanRunsVsStrikeRate(raina, "SK Raina")
p2 <-batsmanRunsVsStrikeRate(dhoni,"MS Dhoni")
p3 <-batsmanRunsVsStrikeRate(sehwag,"V Sehwag")
p4 <-batsmanRunsVsStrikeRate(gambhir,"G Gambhir")
p5 <-batsmanRunsVsStrikeRate(rsharma,"RG Sharma")
p6 <-batsmanRunsVsStrikeRate(kohli,"V Kohli")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

runsSR-1

7. Batsman moving average (in IPL matches)

Rohit Sharma seems to maintain an average of almost 30 runs, while Dhoni and Kohli average around 25.

p1 <-batsmanMovingAverage(raina, "SK Raina")
p2 <-batsmanMovingAverage(dhoni,"MS Dhoni")
p3 <-batsmanMovingAverage(sehwag,"V Sehwag")
p4 <-batsmanMovingAverage(gambhir,"G Gambhir")
p5 <-batsmanMovingAverage(rsharma,"RG Sharma")
p6 <-batsmanMovingAverage(kohli,"V Kohli")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

ma-1

8. Batsman cumulative average (in IPL matches)

The cumulative runs average of Raina, Gambhir, Kohli and Rohit Sharma are around 28-30 runs.Dhoni drops to 25

p1 <-batsmanCumulativeAverageRuns(raina, "SK Raina")
p2 <-batsmanCumulativeAverageRuns(dhoni,"MS Dhoni")
p3 <-batsmanCumulativeAverageRuns(sehwag,"V Sehwag")
p4 <-batsmanCumulativeAverageRuns(gambhir,"G Gambhir")
p5 <-batsmanCumulativeAverageRuns(rsharma,"RG Sharma")
p6 <-batsmanCumulativeAverageRuns(kohli,"V Kohli")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

cAvg-1

9. Cumulative Average Strike Rate (in IPL matches)

As seen above Sehwag has a phenomenal cumulative strike rate of around 150, followed by Dhoni around 130, then we Raina and finally Kohli.

p1 <-batsmanCumulativeStrikeRate(raina, "SK Raina")
p2 <-batsmanCumulativeStrikeRate(dhoni,"MS Dhoni")
p3 <-batsmanCumulativeStrikeRate(sehwag,"V Sehwag")
p4 <-batsmanCumulativeStrikeRate(gambhir,"G Gambhir")
p5 <-batsmanCumulativeStrikeRate(rsharma,"RG Sharma")
p6 <-batsmanCumulativeStrikeRate(kohli,"V Kohli")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

cSR-1

10. Batsman runs against opposition (in IPL matches)

The following charts show the performance of te batsmen against opposing IPL teams


batsmanRunsAgainstOpposition(raina, "SK Raina")

runsOppn1-1

batsmanRunsAgainstOpposition(dhoni,"MS Dhoni")

runsOppn2-1

batsmanRunsAgainstOpposition(sehwag,"V Sehwag")

runsOppn3-1

batsmanRunsAgainstOpposition(gambhir,"G Gambhir")

runsOppn4-1

batsmanRunsAgainstOpposition(rsharma,"RG Sharma")

runsOppn5-1

batsmanRunsAgainstOpposition(kohli,"V Kohli")

runsOppn6-1

11. Runs at different venues (in IPL matches)

The plots below give the performances of the batsmen at different grounds.

batsmanRunsVenue(raina, "SK Raina")

runsVenue1-1

batsmanRunsVenue(dhoni,"MS Dhoni")

runsVenue2-1

batsmanRunsVenue(sehwag,"V Sehwag")

runsVenue3-1

batsmanRunsVenue(gambhir,"G Gambhir")

runsVenue4-1

batsmanRunsVenue(rsharma,"RG Sharma")

runsVenue5-1

batsmanRunsVenue(kohli,"V Kohli")

runsVenue6-1

12. Predict number of runs to deliveries (in IPL matches)

The plots below use rpart classification tree to predict the number of deliveries required to score the runs in the leaf node.

par(mfrow=c(1,3))
par(mar=c(4,4,2,2))
batsmanRunsPredict(raina, "SK Raina")
batsmanRunsPredict(dhoni,"MS Dhoni")
batsmanRunsPredict(sehwag,"V Sehwag")

runsPredict1,runsVenue1-1

par(mfrow=c(1,3))
par(mar=c(4,4,2,2))
batsmanRunsPredict(gambhir,"G Gambhir")
batsmanRunsPredict(rsharma,"RG Sharma")
batsmanRunsPredict(kohli,"V Kohli")

runsPredict2,runsVenue1-1

B. Bowler functions

13. Get bowling details in IPL matches

The function below gets the overall team IPL T20 bowling details based on the RData file available in IPL T20 matches. This is currently also available in Github at [yorkrData] (https://github.com/tvganesh/yorkrData/tree/master/IPL/IPL-T20-matches). The IPL T20 bowling details of the IPL team in each match is created, and a huge data frame is created by rbinding the individual dataframes. This can be saved as a RData file

setwd("C:/software/cricket-package/york-test/yorkrData/IPL/IPL-T20-matches")
kkr_bowling <- getTeamBowlingDetails("Kolkata Knight Riders",dir=".",save=TRUE)
csk_bowling <- getTeamBowlingDetails("Chennai Super Kings",dir=".",save=TRUE)
kxip_bowling <- getTeamBowlingDetails("Kings XI Punjab",dir=".",save=TRUE)
mi_bowling <- getTeamBowlingDetails("Mumbai Indians",dir=".",save=TRUE)
rcb_bowling <- getTeamBowlingDetails("Royal Challengers Bangalore",dir=".",save=TRUE)
rr_bowling <- getTeamBowlingDetails("Rajasthan Royals",dir=".",save=TRUE)
fl <- list.files(".","BowlingDetails.RData")
file.copy(fl, "C:/software/cricket-package/cricsheet/cleanup/IPL/part4")

14. Get bowling details of the individual IPL bowlers

This function is used to get the individual bowling record for a specified bowler of the country as in the functions below. For analyzing the bowling performances the following cricketers have been chosen based on the bowling scorecard from my post yorkr crashes the IPL party ! – Part 3

  1. Ravichander Ashwin (CSK)
  2. DJ Bravo (CSK)
  3. PP Chawla (KXIP)
  4. Harbhajan Singh (MI)
  5. R Vinay Kumar (RCB)
  6. SK Trivedi (RR)
setwd("C:/software/cricket-package/cricsheet/cleanup/IPL/part4")
ashwin <- getBowlerWicketDetails(team="Chennai Super Kings",name="R Ashwin",dir=".")
bravo <-  getBowlerWicketDetails(team="Chennai Super Kings",name="DJ Bravo",dir=".")
chawla <-  getBowlerWicketDetails(team="Kings XI Punjab",name="PP Chawla",dir=".")
harbhajan <-  getBowlerWicketDetails(team="Mumbai Indians",name="Harbhajan Singh",dir=".")
vinay <-  getBowlerWicketDetails(team="Royal Challengers Bangalore",name="R Vinay Kumar",dir=".")
sktrivedi <-  getBowlerWicketDetails(team="Rajasthan Royals",name="SK Trivedi",dir=".")

15. Bowler Mean Economy Rate (in IPL matches)

Ashwin & Chawla have the best economy rates of in the IPL teams, followed by Harbhajan Singh

p1<-bowlerMeanEconomyRate(ashwin,"R Ashwin")
p2<-bowlerMeanEconomyRate(bravo, "DJ Bravo")
p3<-bowlerMeanEconomyRate(chawla, "PP Chawla")
p4<-bowlerMeanEconomyRate(harbhajan, "Harbhajan Singh")
p5<-bowlerMeanEconomyRate(vinay, "R Vinay")
p6<-bowlerMeanEconomyRate(sktrivedi, "SK Trivedi")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

meanER-1

16. Bowler Mean Runs conceded (in IPL matches)

p1<-bowlerMeanRunsConceded(ashwin,"R Ashwin")
p2<-bowlerMeanRunsConceded(bravo, "DJ Bravo")
p3<-bowlerMeanRunsConceded(chawla, "PP Chawla")
p4<-bowlerMeanRunsConceded(harbhajan, "Harbhajan Singh")
p5<-bowlerMeanRunsConceded(vinay, "R Vinay")
p6<-bowlerMeanRunsConceded(sktrivedi, "SK Trivedi")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

meanRunsConceded-1

17. Bowler Moving average (in IPL matches)

Harbhajan’s moving average is the best hovering around 2 wickets

p1<-bowlerMovingAverage(ashwin,"R Ashwin")
p2<-bowlerMovingAverage(bravo, "DJ Bravo")
p3<-bowlerMovingAverage(chawla, "PP Chawla")
p4<-bowlerMovingAverage(harbhajan, "Harbhajan Singh")
p5<-bowlerMovingAverage(vinay, "R Vinay")
p6<-bowlerMovingAverage(sktrivedi, "SK Trivedi")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

bowlerMA-1

17. Bowler cumulative average wickets (in IPL matches)

The cumulative average tells a different story. DJ Bravo and R Vinay have a cumulative average of 2 wickets. All others are around 1.5

p1<-bowlerCumulativeAvgWickets(ashwin,"R Ashwin")
p2<-bowlerCumulativeAvgWickets(bravo, "DJ Bravo")
p3<-bowlerCumulativeAvgWickets(chawla, "PP Chawla")
p4<-bowlerCumulativeAvgWickets(harbhajan, "Harbhajan Singh")
p5<-bowlerCumulativeAvgWickets(vinay, "R Vinay")
p6<-bowlerCumulativeAvgWickets(sktrivedi, "SK Trivedi")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

cumWkts-1

18. Bowler cumulative Economy Rate (ER) (in IPL matches)

Ashwin & Harbhajan have the best cumulative economy rate

p1<-bowlerCumulativeAvgEconRate(ashwin,"R Ashwin")
p2<-bowlerCumulativeAvgEconRate(bravo, "DJ Bravo")
p3<-bowlerCumulativeAvgEconRate(chawla, "PP Chawla")
p4<-bowlerCumulativeAvgEconRate(harbhajan, "Harbhajan Singh")
p5<-bowlerCumulativeAvgEconRate(vinay, "R Vinay")
p6<-bowlerCumulativeAvgEconRate(sktrivedi, "SK Trivedi")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

cumER-1

19. Bowler wicket plot (in IPL matches)

The plot below gives the average wickets versus number of overs

p1<-bowlerWicketPlot(ashwin,"R Ashwin")
p2<-bowlerWicketPlot(bravo, "DJ Bravo")
p3<-bowlerWicketPlot(chawla, "PP Chawla")
p4<-bowlerWicketPlot(harbhajan, "Harbhajan Singh")
p5<-bowlerWicketPlot(vinay, "R Vinay")
p6<-bowlerWicketPlot(sktrivedi, "SK Trivedi")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

wktPlot-1

20. Bowler wicket against opposing IPL teams

bowlerWicketsAgainstOpposition(ashwin,"R Ashwin")

wktsOppn1-1

bowlerWicketsAgainstOpposition(bravo, "DJ Bravo")

wktsOppn2-1

bowlerWicketsAgainstOpposition(chawla, "PP Chawla")

wktsOppn3-1

bowlerWicketsAgainstOpposition(harbhajan, "Harbhajan Singh")

wktsOppn4-1

bowlerWicketsAgainstOpposition(vinay, "R Vinay")

wktsOppn5-1

bowlerWicketsAgainstOpposition(sktrivedi, "SK Trivedi")

wktsOppn6-1

21. Bowler wicket at cricket grounds in IPL

bowlerWicketsVenue(ashwin,"R Ashwin")

wktsAve1-1

bowlerWicketsVenue(bravo, "DJ Bravo")

wktsAve2-1

bowlerWicketsVenue(chawla, "PP Chawla")

wktsAve3-1

bowlerWicketsVenue(harbhajan, "Harbhajan Singh")

wktsAve4-1

bowlerWicketsVenue(vinay, "R Vinay")

wktsAve5-1

bowlerWicketsVenue(sktrivedi, "SK Trivedi")

wktsAve6-1

22. Get Delivery wickets for IPL bowlers

This function creates a dataframe of deliveries and the wickets taken

setwd("C:/software/cricket-package/york-test/yorkrData/IPL/IPL-T20-matches")
ashwin1 <- getDeliveryWickets(team="Chennai Super Kings",dir=".",name="R Ashwin",save=FALSE)
bravo1 <- getDeliveryWickets(team="Chennai Super Kings",dir=".",name="DJ Bravo",save=FALSE)
chawla1 <- getDeliveryWickets(team="Kings XI Punjab",dir=".",name="PP Chawla",save=FALSE)
harbhajan1 <- getDeliveryWickets(team="Mumbai Indians",dir=".",name="Harbhajan Singh",save=FALSE)
vinay1 <- getDeliveryWickets(team="Royal Challengers Bangalore",dir=".",name="R Vinay",save=FALSE)
sktrivedi1 <- getDeliveryWickets(team="Rajasthan Royals",dir=".",name="SK Trivedi",save=FALSE)

23. Predict number of deliveries to wickets in IPL T20

#Ashwin takes 
par(mfrow=c(1,2))
par(mar=c(4,4,2,2))

bowlerWktsPredict(ashwin1,"R Ashwin")
bowlerWktsPredict(bravo1, "DJ Bravo")

wktsPred1-1

par(mfrow=c(1,2))
par(mar=c(4,4,2,2))
bowlerWktsPredict(chawla1, "PP Chawla")
bowlerWktsPredict(harbhajan1, "Harbhajan Singh")

wktsPred2-1

par(mfrow=c(1,2))
par(mar=c(4,4,2,2))
bowlerWktsPredict(vinay1, "R Vinay")
bowlerWktsPredict(sktrivedi1, "SK Trivedi")

wktsPred3-1

Conclusion

This concludes the 4 part writeup of yorkr’s handling of IPL Twenty20’s. You can fork/clone the code from Github at yorkr.

As I mentioned earlier, this brings to a close to all my posts based on my R cricket package yorkr. I do have a couple of more ideas, but this will take some time I think.

Hope you have a great time with my yorkr package!

Till next time, adieu!

Also see

  1. Introducing cricket package yorkr: Part 3-Foxed by flight!
  2. Introducing cricketr! : An R package to analyze performances of cricketers
  3. Cricket analytics with cricketr in paperback and Kindle versions
  4. Bend it like Bluemix, MongoDB with auto-scaling – Part 1
  5. The dark side of the Internet
  6. Modeling a Car in Android
  7. yorkr pads up for the Twenty20s: Part 1- Analyzing team”s match performance
  8. Cricket analytics with cricketr

yorkr crashes the IPL party! – Part 3!


Introduction

“I’m sorry, if you were right, I’d agree with you.”

                 Robin Williams

Get your facts first. Then you can distort them as you please.

                 Mark Twain
                 

Do not take life too seriously. You will never get out of it alive.

                 Elbert Hubbard

This is the 3rd post in the “yorkr crashes the IPL party!” series. The 2 earlier ones were

  1. yorkr crashes the IPL party ! – Part 1
  2. yorkr crashes the IPL party ! – Part 2

This post deals with Class 3 functions, namely the performances of an IPL team in all matches against all other IPL teams matches for e.g Chennai Super Kings against all other IPL teams or Delhi Daredevils against all other teams.

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 has also been published at RPubs IPLT20-Part3 and can also be downloaded as a PDF document from IPLT20-Part3.pdf.

You can clone/fork the code for the package yorkr from Github at yorkr-package

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

The list of functions in Class 3 are

  1. teamBattingScorecardAllOppnAllMatches()
  2. teamBatsmenPartnershipAllOppnAllMatches()
  3. teamBatsmenPartnershipAllOppnAllMatchesPlot()
  4. teamBatsmenVsBowlersAllOppnAllMatchesRept()
  5. teamBatsmenVsBowlersAllOppnAllMatchesPlot()
  6. teamBowlingScorecardAllOppnAllMatchesMain()
  7. teamBowlersVsBatsmenAllOppnAllMatchesRept()
  8. teamBowlersVsBatsmenAllOppnAllMatchesPlot()
  9. teamBowlingWicketKindAllOppnAllMatches()
  10. teamBowlingWicketRunsAllOppnAllMatches()

Note: As in the previous parts the plots usually have the plot=TRUE/FALSE parameter. This is to allow the user to get a return value of the desired dataframe. The user can choose to plot this, in any way he/she likes for e.g in interactive charts using rcharts, ggvis,googleVis,plotly etc

1. Install the package from CRAN

The yorkr package can be installed directly from CRAN now! Install the yorkr package.

if (!require("yorkr")) {
  install.packages("yorkr") 
  library("yorkr")
}
rm(list=ls())

2. Get data for all matches against all oppositions for a team

We can get all IPL matches against all other IPL teams using the function below. The dir parameter should point to the folder in which the RData files where the individual IPL T20 matches exist. This function creates a data frame of all the matches and also saves the resulting dataframe as RData

setwd("C:/software/cricket-package/york-test/yorkrData/IPL/IPL-T20-team-allMatches-allOppostions")
# Get all matches against all oppositions for India and save as RData
matches <-getAllMatchesAllOpposition("Royal Challengers Bangalore",dir=".",save=TRUE)
dim(matches)
## [1] 28199    25

“`

3. Save data for all matches against all oppositions

This can be done locally using the function below. This function gets all the IPL T20 matches of the IPL team against all other IPL teams and combines them into a single dataframe and saves it in the current folder. The current implementation expects 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. However you will need to use this function for future matches!

# To be available in yorkr_0.0.5. You can install from Github though.
#saveAllMatchesAllOppositionIPLT20()

4. Load data directly for all matches between 2 teams

As in my earlier posts (IPLT20-Part1 & IPLT20-Part2) I have however already saved the data, for all IPL matches of the individual IPL teams, against all other IPL teams. The data for these matches for the individual IPL teams can be downloaded directly from Github folder at IPL-T20-team-allmatches-allOppositions

Note: The dataframe for the different for all the matches of a IPL team against all other IPL teams can be loaded directly into your code.Feel free to download the zip of the data and to perform any data mining on them.

If you do come up with interesting insights, I would appreciate if attribute the source to Cricsheet(http://cricsheet.org), and my package yorkr and my blog Giga thoughts, besides dropping me a note.*

As in my earlier post I will be directly loading the saved files. For the illustration of the functions, I will any random IPL team for the funtions for illustration

setwd("C:/software/cricket-package/york-test/yorkrData/IPL/IPL-T20-team-allMatches-allOppostions")
load("allMatchesAllOpposition-Chennai Super Kings.RData")
csk_Allmatches <- matches
load("allMatchesAllOpposition-Deccan Chargers.RData")
dc_Allmatches <- matches
load("allMatchesAllOpposition-Delhi Daredevils.RData")
dd_Allmatches <- matches
load("allMatchesAllOpposition-Kings XI Punjab.RData")
kxip_Allmatches <- matches
load("allMatchesAllOpposition-Kochi Tuskers Kerala.RData")
ktk_Allmatches <- matches
load("allMatchesAllOpposition-Kolkata Knight Riders.RData")
kkr_Allmatches <- matches
load("allMatchesAllOpposition-Mumbai Indians.RData")
mi_Allmatches <- matches
load("allMatchesAllOpposition-Pune Warriors.RData")
pw_Allmatches <- matches
load("allMatchesAllOpposition-Rajasthan Royals.RData")
rr_Allmatches <- matches
load("allMatchesAllOpposition-Royal Challengers Bangalore.RData")
rcb_Allmatches <- matches
load("allMatchesAllOpposition-Sunrisers Hyderabad.RData")
sh_Allmatches <- matches

5. Team IPL T20 Batting Scorecard (all matches with all opposing IPL teams)

The following functions shows the batting scorecards for each IPL team. It returns a dataframe with the top batsmen in each IPL team

#Top IPL Twenty20 batsmen for Chennai Super Kings
m <-teamBattingScorecardAllOppnAllMatches(csk_Allmatches,theTeam="Chennai Super Kings")
## Total= 19312
m
## Source: local data frame [46 x 5]
## 
##         batsman ballsPlayed fours sixes  runs
##          (fctr)       (int) (int) (int) (dbl)
## 1      SK Raina        2513   312   144  3567
## 2      MS Dhoni        2036   206   121  2887
## 3    MEK Hussey        1361   178    43  1721
## 4       M Vijay        1220   140    64  1574
## 5   S Badrinath        1171   152    28  1427
## 6  F du Plessis         837    92    29  1081
## 7     ML Hayden         725   118    43  1077
## 8      DR Smith         673    98    42   886
## 9     JA Morkel         549    50    47   812
## 10  BB McCullum         562    78    42   809
## ..          ...         ...   ...   ...   ...
#Top IPL Twenty20 batsmen for Deccan Chargers
m <-teamBattingScorecardAllOppnAllMatches(dc_Allmatches,theTeam="Deccan Chargers")
## Total= 10885
m
## Source: local data frame [58 x 5]
## 
##            batsman ballsPlayed fours sixes  runs
##             (fctr)       (int) (int) (int) (dbl)
## 1     AC Gilchrist         802   136    64  1220
## 2        RG Sharma         866    96    51  1170
## 3         S Dhawan         737   106    25   969
## 4        A Symonds         600    65    38   839
## 5         HH Gibbs         695    75    29   805
## 6         CL White         425    47    22   583
## 7    KC Sangakkara         458    65     9   558
## 8         TL Suman         437    41    20   544
## 9        JP Duminy         360    22    19   449
## 10 Y Venugopal Rao         357    32    19   446
## ..             ...         ...   ...   ...   ...
#Top IPL Twenty20 batsmen for Delhi Daredevils
m <-teamBattingScorecardAllOppnAllMatches(dd_Allmatches,theTeam="Delhi Daredevils")
## Total= 16324
m
## Source: local data frame [76 x 5]
## 
##             batsman ballsPlayed fours sixes  runs
##              (fctr)       (int) (int) (int) (dbl)
## 1          V Sehwag        1290   257    84  2127
## 2         DA Warner        1050   146    58  1435
## 3         G Gambhir         828   126    12  1058
## 4        KD Karthik         762    82    27   979
## 5         JP Duminy         585    44    40   796
## 6  DPMD Jayawardene         600    79     9   666
## 7    AB de Villiers         541    50    13   650
## 8      KP Pietersen         431    56    27   599
## 9        TM Dilshan         452    62    16   562
## 10        KM Jadhav         394    42    19   537
## ..              ...         ...   ...   ...   ...
#Top IPL Twenty20 batsmen for Kolkata Knight Riders
m <-teamBattingScorecardAllOppnAllMatches(kkr_Allmatches,theTeam="Kolkata Knight Riders")
## Total= 16001
m
## Source: local data frame [69 x 5]
## 
##        batsman ballsPlayed fours sixes  runs
##         (fctr)       (int) (int) (int) (dbl)
## 1    G Gambhir        1583   235    33  2024
## 2    YK Pathan         937   100    64  1317
## 3    JH Kallis        1193   128    23  1294
## 4   SC Ganguly         909   105    36  1031
## 5   RV Uthappa         739   118    25  1024
## 6    MK Tiwary         878    86    23  1002
## 7  BB McCullum         709    92    32   882
## 8    MK Pandey         518    58    17   626
## 9     MS Bisla         470    60    16   542
## 10   DJ Hussey         389    31    28   511
## ..         ...         ...   ...   ...   ...
#Top IPL Twenty20 batsmen for Kochi Tuskers Kerala
m <-teamBattingScorecardAllOppnAllMatches(ktk_Allmatches,theTeam="Kochi Tuskers Kerala")
## Total= 1758
m
## Source: local data frame [19 x 5]
## 
##             batsman ballsPlayed fours sixes  runs
##              (fctr)       (int) (int) (int) (dbl)
## 1       BB McCullum         265    35    16   357
## 2  DPMD Jayawardene         249    35     5   299
## 3          BJ Hodge         230    26     9   285
## 4         RA Jadeja         225    20    14   283
## 5          PA Patel         181    25     2   202
## 6         M Klinger          74     9    NA    73
## 7     R Vinay Kumar          47     4     1    50
## 8          RV Gomez          47     4     1    46
## 9        VVS Laxman          38     3     2    44
## 10          OA Shah          14     1     2    26
## 11      NLTC Perera          27     4    NA    23
## 12 Y Gnaneswara Rao          17     3    NA    19
## 13        KM Jadhav          23     1    NA    18
## 14          B Akhil           9    NA     1    13
## 15         RR Powar          13    NA    NA    11
## 16   M Muralitharan           6    NA    NA     5
## 17         RP Singh           3    NA    NA     2
## 18      S Sreesanth           8    NA    NA     1
## 19   P Parameswaran           1    NA    NA     1
#Top IPL Twenty20 batsmen for Kings XI Punjab
m <-teamBattingScorecardAllOppnAllMatches(kxip_Allmatches,theTeam="Kings XI Punjab")
## Total= 17333
m
## Source: local data frame [74 x 5]
## 
##             batsman ballsPlayed fours sixes  runs
##              (fctr)       (int) (int) (int) (dbl)
## 1          SE Marsh        1444   211    65  1973
## 2         DA Miller         865    89    70  1319
## 3     KC Sangakkara         755   117    18  1000
## 4      Yuvraj Singh         643    67    46   859
## 5      AC Gilchrist         636   103    28   849
## 6  DPMD Jayawardene         546    81    24   792
## 7     Mandeep Singh         616    96     8   763
## 8        GJ Maxwell         388    61    44   697
## 9         DJ Hussey         567    51    26   695
## 10          WP Saha         437    49    28   611
## ..              ...         ...   ...   ...   ...
#Top IPL Twenty20 batsmen for Mumbai Indians
m <-teamBattingScorecardAllOppnAllMatches(mi_Allmatches,theTeam="Mumbai Indians")
## Total= NA
m
## Source: local data frame [73 x 5]
## 
##          batsman ballsPlayed fours sixes  runs
##           (fctr)       (int) (int) (int) (dbl)
## 1   SR Tendulkar        1806   277    29  2221
## 2      RG Sharma        1657   176    96  2201
## 3      AT Rayudu        1507   169    63  1963
## 4     KA Pollard        1117   116   106  1707
## 5    LMP Simmons         720    99    35   934
## 6  ST Jayasuriya         504    84    37   748
## 7     KD Karthik         591    82    16   727
## 8       DR Smith         449    62    26   600
## 9      JP Duminy         437    39    16   523
## 10     SS Tiwary         332    32    19   458
## ..           ...         ...   ...   ...   ...
#Top IPL Twenty20 batsmen for Pune Warriors
m <-teamBattingScorecardAllOppnAllMatches(pw_Allmatches,theTeam="Pune Warriors")
## Total= 5871
m
## Source: local data frame [43 x 5]
## 
##         batsman ballsPlayed fours sixes  runs
##          (fctr)       (int) (int) (int) (dbl)
## 1    RV Uthappa         880   106    30  1078
## 2  Yuvraj Singh         427    38    30   551
## 3      JD Ryder         396    60    19   548
## 4     SPD Smith         388    39    18   521
## 5     MK Pandey         421    44    14   459
## 6      AJ Finch         293    52    13   408
## 7    SC Ganguly         321    33     6   318
## 8    AD Mathews         246    10    14   299
## 9      M Manhas         234    19     8   247
## 10     MR Marsh         153     8    13   190
## ..          ...         ...   ...   ...   ...
#Top Twenty20 batsmen for Rajasthan Royals
m <-teamBattingScorecardAllOppnAllMatches(rr_Allmatches,theTeam="Rajasthan Royals")
## Total= 16359
m
## Source: local data frame [80 x 5]
## 
##      batsman ballsPlayed fours sixes  runs
##       (fctr)       (int) (int) (int) (dbl)
## 1  SR Watson        1609   237   107  2342
## 2  AM Rahane        1637   218    38  2031
## 3   R Dravid        1098   171    10  1247
## 4  YK Pathan         601    89    59   990
## 5  SV Samson         596    59    30   740
## 6   GC Smith         601    88     9   697
## 7   BJ Hodge         423    41    24   592
## 8  STR Binny         438    43    21   572
## 9    KK Nair         369    56    14   511
## 10   NV Ojha         385    49    25   501
## ..       ...         ...   ...   ...   ...
#Top IPL Twenty20 batsmen for Royal Challengers Bangalore
m <-teamBattingScorecardAllOppnAllMatches(rcb_Allmatches,theTeam="Royal Challengers Bangalore")
## Total= 17288
m
## Source: local data frame [85 x 5]
## 
##           batsman ballsPlayed fours sixes  runs
##            (fctr)       (int) (int) (int) (dbl)
## 1         V Kohli        2470   274   111  3125
## 2        CH Gayle        1704   217   204  2736
## 3  AB de Villiers        1170   167    90  1899
## 4       JH Kallis         952   123    20  1093
## 5        R Dravid         706    96    17   889
## 6      TM Dilshan         510    78     8   587
## 7      RV Uthappa         380    39    30   549
## 8       SS Tiwary         456    26    17   487
## 9     LRPL Taylor         318    33    28   464
## 10     MA Agarwal         332    41    22   433
## ..            ...         ...   ...   ...   ...
#Top IPL Twenty20 batsmen for Sunrisers Hyderabad
m <-teamBattingScorecardAllOppnAllMatches(sh_Allmatches,theTeam="Sunrisers Hyderabad")
## Total= 6117
m
## Source: local data frame [32 x 5]
## 
##         batsman ballsPlayed fours sixes  runs
##          (fctr)       (int) (int) (int) (dbl)
## 1     DA Warner         715   104    45  1090
## 2      S Dhawan         835   131    18  1040
## 3       NV Ojha         277    26    21   369
## 4      AJ Finch         251    31     9   309
## 5      KL Rahul         284    20     8   308
## 6  MC Henriques         220    20    13   296
## 7      PA Patel         244    37     4   292
## 8     GH Vihari         281    23     1   261
## 9     DJG Sammy         198    14    17   259
## 10    KV Sharma         191    10    11   227
## ..          ...         ...   ...   ...   ...

6. Team Batting Scorecard in IPL Twenty20 matches against all opposing IPL teams

The following functions show the best batsmen from the opposition ‘theTeam’ in the ‘matches’. For e.g. when the matches=csk_Allmatches and theTeam=“Royal Challengers Bangalore” then the returned dataframe shows the best Royal Challengers Bangalore batsmen against CSK

#Top IPL T20  Royal Challengers Bangalore batsmen against Chennai Super Kings
m <-teamBattingScorecardAllOppnAllMatches(matches=csk_Allmatches,theTeam="Royal Challengers Bangalore")
## Total= 2485
m
## Source: local data frame [54 x 5]
## 
##           batsman ballsPlayed fours sixes  runs
##            (fctr)       (int) (int) (int) (dbl)
## 1         V Kohli         542    49    30   694
## 2        CH Gayle         204    12    23   270
## 3  AB de Villiers         147    26     9   241
## 4        R Dravid         111    18    NA   133
## 5      MA Agarwal          96    15     4   120
## 6      RV Uthappa          71     7     8   115
## 7       JH Kallis          95    19    NA   109
## 8       SS Tiwary          84     4     3    86
## 9       MK Pandey          67    10    NA    73
## 10    LRPL Taylor          62     2     3    64
## ..            ...         ...   ...   ...   ...
#Top IPL T20 Mumbai Indians batsmen against Chennai Super Kings
m <-teamBattingScorecardAllOppnAllMatches(matches=csk_Allmatches,theTeam="Mumbai Indians")
## Total= 3223
m
## Source: local data frame [43 x 5]
## 
##            batsman ballsPlayed fours sixes  runs
##             (fctr)       (int) (int) (int) (dbl)
## 1        RG Sharma         343    37    14   444
## 2       KA Pollard         209    25    26   351
## 3     SR Tendulkar         259    38     5   320
## 4        AT Rayudu         243    17    14   299
## 5      LMP Simmons         219    23    16   281
## 6    ST Jayasuriya          91    21    13   190
## 7  Harbhajan Singh         115    13    12   170
## 8         DR Smith          90    16    10   159
## 9         AM Nayar          59    10     6   113
## 10      KD Karthik         100    13     2   109
## ..             ...         ...   ...   ...   ...
#Top IPL T20 Rajasthan Royals batsmen against Pune Warriors
m <-teamBattingScorecardAllOppnAllMatches(pw_Allmatches,theTeam="Rajasthan Royals")
## Total= 743
m
## Source: local data frame [13 x 5]
## 
##        batsman ballsPlayed fours sixes  runs
##         (fctr)       (int) (int) (int) (dbl)
## 1    AM Rahane         134    18     2   173
## 2    SR Watson         100    17     9   165
## 3     R Dravid         140    25     1   165
## 4   AL Menaria          42     1     3    47
## 5  LRPL Taylor          33     4     2    47
## 6     BJ Hodge          37     3    NA    40
## 7    STR Binny          22     2     2    39
## 8  JP Faulkner          16     1     1    22
## 9      J Botha          20     2    NA    19
## 10   DH Yagnik           8     2    NA    12
## 11   SV Samson           6     2    NA    10
## 12     OA Shah           7    NA    NA     4
## 13 MDKJ Perera           1    NA    NA     0
#Top IPL T20 Sunrisers Hyderabad batsmen against West Indies
m <-teamBattingScorecardAllOppnAllMatches(kkr_Allmatches,theTeam="Sunrisers Hyderabad")
## Total= 814
m
## Source: local data frame [27 x 5]
## 
##            batsman ballsPlayed fours sixes  runs
##             (fctr)       (int) (int) (int) (dbl)
## 1         S Dhawan         138    19     3   159
## 2        DA Warner          76    14     6   133
## 3         PA Patel          65     9     1    74
## 4          NV Ojha          56     7     5    66
## 5        DJG Sammy          44     1     5    53
## 6     MC Henriques          38     3     2    48
## 7        KV Sharma          35     1     3    46
## 8      NLTC Perera          34     2     1    40
## 9         CL White          33     3     1    36
## 10 Y Venugopal Rao          24     4    NA    27
## ..             ...         ...   ...   ...   ...

7. Team Batting Partnerships of an IL T20 matches against all opposing teams

This gives the top batting partnerships in each IPL team in all its matches against all opposing teams. The report can either be a ‘summary’ or a ‘detailed’ breakup of the batting partnerships.

# The function gives the names of highest IPL T20 partnership for Chennai Super Kings. The default report parameter is "summary"
m <- teamBatsmenPartnershipAllOppnAllMatches(csk_Allmatches,theTeam='Chennai Super Kings')
m
## Source: local data frame [46 x 2]
## 
##         batsman totalRuns
##          (fctr)     (dbl)
## 1      SK Raina      3567
## 2      MS Dhoni      2887
## 3    MEK Hussey      1721
## 4       M Vijay      1574
## 5   S Badrinath      1427
## 6  F du Plessis      1081
## 7     ML Hayden      1077
## 8      DR Smith       886
## 9     JA Morkel       812
## 10  BB McCullum       809
## ..          ...       ...
# When the report parameter is 'detailed' then the detailed break up of the T20 partnership is returned as a data frame
m <- teamBatsmenPartnershipAllOppnAllMatches(csk_Allmatches,theTeam='Chennai Super Kings',report="detailed")
head(m,30)
##     batsman   nonStriker partnershipRuns totalRuns
## 1  SK Raina   SP Fleming              20      3567
## 2  SK Raina   S Anirudha              33      3567
## 3  SK Raina  S Badrinath             413      3567
## 4  SK Raina     MS Dhoni             546      3567
## 5  SK Raina    JA Morkel             142      3567
## 6  SK Raina      MS Gony              10      3567
## 7  SK Raina    ML Hayden             219      3567
## 8  SK Raina     JDP Oram               6      3567
## 9  SK Raina     DR Smith             239      3567
## 10 SK Raina      M Vijay             325      3567
## 11 SK Raina      JM Kemp              10      3567
## 12 SK Raina     R Ashwin               0      3567
## 13 SK Raina   MEK Hussey             617      3567
## 14 SK Raina F du Plessis             336      3567
## 15 SK Raina    RA Jadeja              50      3567
## 16 SK Raina     DJ Bravo              87      3567
## 17 SK Raina     PA Patel             166      3567
## 18 SK Raina     S Vidyut               1      3567
## 19 SK Raina   A Flintoff              30      3567
## 20 SK Raina      WP Saha              16      3567
## 21 SK Raina  BB McCullum             186      3567
## 22 SK Raina    GJ Bailey              10      3567
## 23 SK Raina    DJ Hussey              95      3567
## 24 SK Raina      M Ntini               2      3567
## 25 SK Raina  C Ganapathy               8      3567
## 26 MS Dhoni   SP Fleming              11      2887
## 27 MS Dhoni   S Anirudha              29      2887
## 28 MS Dhoni     SK Raina             488      2887
## 29 MS Dhoni  S Badrinath             341      2887
## 30 MS Dhoni    JA Morkel             209      2887
#Top IPL T20 Rajasthan Royal partnerships 
teamBatsmenPartnershipAllOppnAllMatches(rr_Allmatches,theTeam='Rajasthan Royals',report="summary")
## Source: local data frame [80 x 2]
## 
##      batsman totalRuns
##       (fctr)     (dbl)
## 1  SR Watson      2342
## 2  AM Rahane      2031
## 3   R Dravid      1247
## 4  YK Pathan       990
## 5  SV Samson       740
## 6   GC Smith       697
## 7   BJ Hodge       592
## 8  STR Binny       572
## 9    KK Nair       511
## 10   NV Ojha       501
## ..       ...       ...
#Top IPL T20 Mumbai Indians batting partnerships 
m <- teamBatsmenPartnershipAllOppnAllMatches(mi_Allmatches,theTeam='Mumbai Indians',report="detailed")
m[1:30,]
##         batsman        nonStriker partnershipRuns totalRuns
## 1  SR Tendulkar     ST Jayasuriya             254      2221
## 2  SR Tendulkar        RV Uthappa              10      2221
## 3  SR Tendulkar          DJ Bravo              66      2221
## 4  SR Tendulkar          AM Nayar              41      2221
## 5  SR Tendulkar   Harbhajan Singh              50      2221
## 6  SR Tendulkar          S Dhawan             183      2221
## 7  SR Tendulkar         JP Duminy             107      2221
## 8  SR Tendulkar            Z Khan               2      2221
## 9  SR Tendulkar           PR Shah              19      2221
## 10 SR Tendulkar         SS Tiwary              81      2221
## 11 SR Tendulkar         AT Rayudu             261      2221
## 12 SR Tendulkar        KA Pollard              65      2221
## 13 SR Tendulkar         R Sathish              62      2221
## 14 SR Tendulkar         R McLaren              33      2221
## 15 SR Tendulkar           RE Levi              14      2221
## 16 SR Tendulkar         RG Sharma             226      2221
## 17 SR Tendulkar      JEC Franklin              82      2221
## 18 SR Tendulkar          DR Smith             187      2221
## 19 SR Tendulkar        KD Karthik             104      2221
## 20 SR Tendulkar        RT Ponting              63      2221
## 21 SR Tendulkar           AP Tare              36      2221
## 22 SR Tendulkar       DJ Thornely              21      2221
## 23 SR Tendulkar          HH Gibbs              13      2221
## 24 SR Tendulkar          TL Suman              19      2221
## 25 SR Tendulkar         A Symonds              13      2221
## 26 SR Tendulkar         DJ Jacobs              68      2221
## 27 SR Tendulkar         AM Rahane              36      2221
## 28 SR Tendulkar Mohammad Ashraful               1      2221
## 29 SR Tendulkar       RJ Peterson               9      2221
## 30 SR Tendulkar       AC Blizzard              77      2221
#Top IPL T20 Royal Challengers Bangalore batting partnerships 
m <-teamBatsmenPartnershipAllOppnAllMatches(rcb_Allmatches,theTeam='Royal Challengers Bangalore',report="detailed")
m[1:30,]
##    batsman      nonStriker partnershipRuns totalRuns
## 1  V Kohli      SP Goswami               7      3125
## 2  V Kohli       JH Kallis             181      3125
## 3  V Kohli        R Dravid              72      3125
## 4  V Kohli   Misbah-ul-Haq              13      3125
## 5  V Kohli      MV Boucher              39      3125
## 6  V Kohli         B Akhil               0      3125
## 7  V Kohli         P Kumar              17      3125
## 8  V Kohli        PA Patel              33      3125
## 9  V Kohli       JA Morkel               2      3125
## 10 V Kohli       MK Pandey              19      3125
## 11 V Kohli      RV Uthappa              32      3125
## 12 V Kohli    KP Pietersen              71      3125
## 13 V Kohli        CL White              25      3125
## 14 V Kohli      TM Dilshan              89      3125
## 15 V Kohli      MA Agarwal              74      3125
## 16 V Kohli  AB de Villiers             582      3125
## 17 V Kohli       SS Tiwary             154      3125
## 18 V Kohli       CA Pujara              56      3125
## 19 V Kohli      DL Vettori              12      3125
## 20 V Kohli        CH Gayle             855      3125
## 21 V Kohli   LA Pomersbach              39      3125
## 22 V Kohli J Syed Mohammad               1      3125
## 23 V Kohli      RR Bhatkal               0      3125
## 24 V Kohli   R Vinay Kumar              21      3125
## 25 V Kohli KB Arun Karthik               2      3125
## 26 V Kohli    Yuvraj Singh             126      3125
## 27 V Kohli          S Rana              23      3125
## 28 V Kohli    NJ Maddinson               6      3125
## 29 V Kohli   Mandeep Singh              23      3125
## 30 V Kohli      KD Karthik              92      3125

8. Batting Partnerships of opposing teams in IPL T20 matches with IPL team

When we use the dataframe rcb_Allmatches (matches of Royal Challengers Bangalore against all opposing teams) and choose another IPL team in the theTeam for e.g Rajasthan Royals then we will get the names of those top Rajasthan Royals batsmen against RCB.

# Top T20 Rajasthan Royals batting partnerships against Royal Challengers Bangalore (report="summary")
m <- teamBatsmenPartnershipAllOppnAllMatches(rcb_Allmatches,theTeam='Rajasthan Royals')
m
## Source: local data frame [50 x 2]
## 
##      batsman totalRuns
##       (fctr)     (dbl)
## 1  SR Watson       271
## 2  AM Rahane       256
## 3   R Dravid       177
## 4   GC Smith       146
## 5    KK Nair        92
## 6  YK Pathan        91
## 7  SPD Smith        91
## 8  SV Samson        87
## 9  STR Binny        80
## 10   NV Ojha        75
## ..       ...       ...
# Top T20 Kolkata Knight Riders  batting partnerships against Sunrisers Hyderabad (report="detailed")
m <- teamBatsmenPartnershipAllOppnAllMatches(sh_Allmatches,theTeam='Kolkata Knight Riders', report="detailed")
m[1:30,]
##             batsman       nonStriker partnershipRuns totalRuns
## 1         YK Pathan          J Botha              14       199
## 2         YK Pathan        PP Chawla              13       199
## 3         YK Pathan        JH Kallis              26       199
## 4         YK Pathan       RV Uthappa               3       199
## 5         YK Pathan        MK Pandey              28       199
## 6         YK Pathan RN ten Doeschate              22       199
## 7         YK Pathan  Shakib Al Hasan              36       199
## 8         YK Pathan         SA Yadav              32       199
## 9         YK Pathan          P Dogra              10       199
## 10        YK Pathan        SP Narine               9       199
## 11        YK Pathan    Iqbal Abdulla               6       199
## 12       RV Uthappa        G Gambhir              65       145
## 13       RV Uthappa        YK Pathan              19       145
## 14       RV Uthappa        MK Pandey              61       145
## 15        G Gambhir         MS Bisla              33       132
## 16        G Gambhir        JH Kallis              30       132
## 17        G Gambhir       RV Uthappa              69       132
## 18        MK Pandey        YK Pathan              31       103
## 19        MK Pandey       RV Uthappa              37       103
## 20        MK Pandey RN ten Doeschate              14       103
## 21        MK Pandey         SA Yadav               5       103
## 22        MK Pandey       AD Russell              16       103
## 23        JH Kallis       EJG Morgan              24        65
## 24        JH Kallis        G Gambhir              27        65
## 25        JH Kallis        YK Pathan              14        65
## 26       EJG Morgan        JH Kallis              56        56
## 27         MS Bisla        G Gambhir              43        43
## 28 RN ten Doeschate        YK Pathan              29        34
## 29 RN ten Doeschate        MK Pandey               5        34
## 30         SA Yadav        YK Pathan              11        20
#Top IPL T20 Chennai Super Kings batting partnerships  against Mumbai Indians
m <- teamBatsmenPartnershipAllOppnAllMatches(mi_Allmatches,theTeam='Chennai Super Kings',report="detailed")
head(m,30)
##     batsman      nonStriker partnershipRuns totalRuns
## 1  SK Raina       ML Hayden             104       537
## 2  SK Raina        PA Patel               5       537
## 3  SK Raina        MS Dhoni              23       537
## 4  SK Raina        DJ Bravo              59       537
## 5  SK Raina     S Badrinath              78       537
## 6  SK Raina         M Vijay              22       537
## 7  SK Raina      MEK Hussey              97       537
## 8  SK Raina    F du Plessis              43       537
## 9  SK Raina        DR Smith              51       537
## 10 SK Raina     BB McCullum               8       537
## 11 SK Raina       DJ Hussey              46       537
## 12 SK Raina      SP Fleming               1       537
## 13 MS Dhoni       ML Hayden              83       466
## 14 MS Dhoni        SK Raina               8       466
## 15 MS Dhoni        JDP Oram              10       466
## 16 MS Dhoni        DJ Bravo              63       466
## 17 MS Dhoni     S Badrinath              55       466
## 18 MS Dhoni Joginder Sharma              19       466
## 19 MS Dhoni         M Vijay               1       466
## 20 MS Dhoni      MEK Hussey               8       466
## 21 MS Dhoni    F du Plessis              24       466
## 22 MS Dhoni       JA Morkel              13       466
## 23 MS Dhoni       RA Jadeja              37       466
## 24 MS Dhoni        R Ashwin              52       466
## 25 MS Dhoni      B Laughlin              16       466
## 26 MS Dhoni      AS Rajpoot               9       466
## 27 MS Dhoni       CH Morris               1       466
## 28 MS Dhoni       MM Sharma              23       466
## 29 MS Dhoni     BB McCullum              14       466
## 30 MS Dhoni          P Negi              30       466
#Top IPL T20 Kochi Tusker Kerala batting partnerships  against Kings XI Punjab
m <- teamBatsmenPartnershipAllOppnAllMatches(kxip_Allmatches,theTeam='Kochi Tuskers Kerala',report="detailed")
head(m,30)
##             batsman       nonStriker partnershipRuns totalRuns
## 1  DPMD Jayawardene        RA Jadeja              12        76
## 2  DPMD Jayawardene      BB McCullum              42        76
## 3  DPMD Jayawardene         BJ Hodge               3        76
## 4  DPMD Jayawardene          OA Shah               9        76
## 5  DPMD Jayawardene         RV Gomez              10        76
## 6       BB McCullum DPMD Jayawardene              32        32
## 7           OA Shah DPMD Jayawardene              23        23
## 8         RA Jadeja DPMD Jayawardene              17        17
## 9          BJ Hodge DPMD Jayawardene               4         4
## 10         RV Gomez DPMD Jayawardene               2         2
## 11    R Vinay Kumar DPMD Jayawardene               1         1
## 12         PA Patel DPMD Jayawardene               0         0

9. Team Batting Partnership plots in Twenty20 matches against all opposing teams

Graphical plot of batting partnerships for the IPL teams

# Plot of IPL T20 batting partnerships of Chennai Super Kings (Suresh Raina  and MS Dhoni have the best IPL T20 partnerships for CSK)
teamBatsmenPartnershipAllOppnAllMatchesPlot(csk_Allmatches,"Chennai Super Kings",main="Chennai Super Kings")

batsmenPartnership1-1

# Plot of T20 batting partnerships of Royal Challengers Bangalore (Virat Kohli  and Chris Gayle lead)
teamBatsmenPartnershipAllOppnAllMatchesPlot(rcb_Allmatches,"Royal Challengers Bangalore",main="Royal Challengers Bangalore")

batsmenPartnership1-2

# Plot of IPL T20 batting partnerships of Kolkata Knight Riders (Gautham Gambhir and Yusuf Pathan head the list)
teamBatsmenPartnershipAllOppnAllMatchesPlot(kkr_Allmatches,"Kolkata Knight Riders",main="Kolkata Knight Riders")

batsmenPartnership1-3

10. Top opposition batting partnerships in IPL Twenty20 matches against all opposing teams

This gives the best performance of the team against a specified IPL team

# Top Sunrisers Hyderabad IPL T20 partnerships against Kings XI Punjab
teamBatsmenPartnershipAllOppnAllMatchesPlot(sh_Allmatches,"Sunrisers Hyderabad",main="Kings XI Punjab")

batsmenPartnership2-1

# Top Delhi Daredevils T20 partnerships against Deccan Chargers
teamBatsmenPartnershipAllOppnAllMatchesPlot(dd_Allmatches,"Delhi Daredevils",main="Deccan Chargers")

batsmenPartnership2-2

# Top Rajasthan Royals T20 partnerships against Chennai Super Kings 
teamBatsmenPartnershipAllOppnAllMatchesPlot(rr_Allmatches,"Rajasthan Royals",main="Chennai Super Kings")

batsmenPartnership2-3

11. Batsmen vs Bowlers in IPL Twenty20 matches against all opposing teams

The function below gives the top performance of batsmen against the opposing teams

# Top IPL T20 Chennai Super Kings batsmen against bowlers when rank=0
m <-teamBatsmenVsBowlersAllOppnAllMatchesRept(csk_Allmatches,"Chennai Super Kings",rank=0)
m
## Source: local data frame [46 x 2]
## 
##         batsman runsScored
##          (fctr)      (dbl)
## 1      SK Raina       3567
## 2      MS Dhoni       2887
## 3    MEK Hussey       1721
## 4       M Vijay       1574
## 5   S Badrinath       1427
## 6  F du Plessis       1081
## 7     ML Hayden       1077
## 8      DR Smith        886
## 9     JA Morkel        812
## 10  BB McCullum        809
## ..          ...        ...
# Performance of IPL T20  Rajasthan Royals batsman in T20 with rank=1 against all other IPL teams. This is Shane Watson for RR
m <-teamBatsmenVsBowlersAllOppnAllMatchesRept(rr_Allmatches,"Rajasthan Royals",rank=1,dispRows=30)
m
## Source: local data frame [30 x 3]
## Groups: batsman [1]
## 
##      batsman          bowler  runs
##       (fctr)          (fctr) (dbl)
## 1  SR Watson        M Kartik    94
## 2  SR Watson       RA Jadeja    73
## 3  SR Watson      SL Malinga    68
## 4  SR Watson         P Kumar    66
## 5  SR Watson       PP Chawla    63
## 6  SR Watson        R Ashwin    59
## 7  SR Watson Shakib Al Hasan    56
## 8  SR Watson  M Muralitharan    54
## 9  SR Watson       MM Sharma    50
## 10 SR Watson        DJ Bravo    49
## ..       ...             ...   ...
# Performance of Kolkata Knight Riders batsman in IPL T20 with rank=2 with all other IPL teams. This is Yusuf Pathan with
m <-teamBatsmenVsBowlersAllOppnAllMatchesRept(kkr_Allmatches,"Kolkata Knight Riders",rank=2,dispRows=30)
m
## Source: local data frame [30 x 3]
## Groups: batsman [1]
## 
##      batsman          bowler  runs
##       (fctr)          (fctr) (dbl)
## 1  YK Pathan        DW Steyn    75
## 2  YK Pathan        A Mishra    63
## 3  YK Pathan      SL Malinga    57
## 4  YK Pathan   R Vinay Kumar    39
## 5  YK Pathan Harbhajan Singh    36
## 6  YK Pathan       KV Sharma    33
## 7  YK Pathan         B Kumar    32
## 8  YK Pathan     Imran Tahir    27
## 9  YK Pathan       S Aravind    26
## 10 YK Pathan        M Morkel    25
## ..       ...             ...   ...

12. Batsmen vs Bowlers in IPL Twenty20 matches against all other IPL teams (continued)

# The RCB IPL T20 batsmen who has the best performance against Sunrisers Hyderabad bowlers
m <-teamBatsmenVsBowlersAllOppnAllMatchesRept(matches=sh_Allmatches,theTeam="Royal Challengers Bangalore",rank=1,dispRows=25)
m
## Source: local data frame [18 x 3]
## Groups: batsman [1]
## 
##    batsman          bowler  runs
##     (fctr)          (fctr) (dbl)
## 1  V Kohli       KV Sharma    48
## 2  V Kohli        A Mishra    35
## 3  V Kohli     NLTC Perera    31
## 4  V Kohli         B Kumar    26
## 5  V Kohli        I Sharma    25
## 6  V Kohli        DW Steyn    23
## 7  V Kohli         P Kumar    21
## 8  V Kohli       IK Pathan    16
## 9  V Kohli        CL White    13
## 10 V Kohli        TA Boult    11
## 11 V Kohli  A Ashish Reddy    10
## 12 V Kohli    Ankit Sharma    10
## 13 V Kohli       DJG Sammy     7
## 14 V Kohli   Parvez Rasool     7
## 15 V Kohli       RS Bopara     3
## 16 V Kohli    MC Henriques     2
## 17 V Kohli       GH Vihari     2
## 18 V Kohli Y Venugopal Rao     1
# All the top IPL T20 Delhi Daredevils batsmen against Kings XI Punjab in all of Indian matches
m <-teamBatsmenVsBowlersAllOppnAllMatchesRept(kxip_Allmatches,"Delhi Daredevils",rank=0)
m
## Source: local data frame [52 x 2]
## 
##             batsman runsScored
##              (fctr)      (dbl)
## 1          V Sehwag        250
## 2         DA Warner        245
## 3         G Gambhir        179
## 4        KD Karthik        175
## 5        MA Agarwal        128
## 6  DPMD Jayawardene        107
## 7      KP Pietersen        107
## 8           NV Ojha         86
## 9          M Manhas         83
## 10  Y Venugopal Rao         72
## ..              ...        ...
# The best Chennai Super Kings IPL T20 batsman(rank=0) against Delhi Daredevils and his performance against England bowlers
m <-teamBatsmenVsBowlersAllOppnAllMatchesRept(dd_Allmatches,"Chennai Super Kings",rank=1,dispRows=30)
m
## Source: local data frame [30 x 3]
## Groups: batsman [1]
## 
##     batsman        bowler  runs
##      (fctr)        (fctr) (dbl)
## 1  MS Dhoni     IK Pathan    33
## 2  MS Dhoni    AB Agarkar    30
## 3  MS Dhoni       A Nehra    29
## 4  MS Dhoni Mohammad Asif    21
## 5  MS Dhoni    JD Unadkat    19
## 6  MS Dhoni      M Morkel    17
## 7  MS Dhoni      UT Yadav    16
## 8  MS Dhoni    GD McGrath    14
## 9  MS Dhoni      V Sehwag    14
## 10 MS Dhoni      S Nadeem    14
## ..      ...           ...   ...
# All the top Deccan Chargers IPL T20 batsmen (rank=0) against Kolkata Knight Riders and performances against Australian bowlers
m <-teamBatsmenVsBowlersAllOppnAllMatchesRept(kkr_Allmatches,"Deccan Chargers",rank=0)
m
## Source: local data frame [29 x 2]
## 
##            batsman runsScored
##             (fctr)      (dbl)
## 1     AC Gilchrist        166
## 2         HH Gibbs        145
## 3        RG Sharma        116
## 4         S Dhawan        111
## 5        A Symonds        100
## 6  Y Venugopal Rao         92
## 7         B Chipli         60
## 8     DB Ravi Teja         54
## 9         TL Suman         53
## 10      VVS Laxman         32
## ..             ...        ...

13. IPL Batsmen vs Bowlers Plot in Twenty20 matches against all other IPL teams

The following functions plot the performances of the IPL batsman based on the rank chosen against all other IPL team’s bowlers. Note: The rank has to be >0

#The following plot displays the performance of the top Royal Challengers Bangalore IPL T20 batsman (rank=1) against all opposition IPL bowlers. This is Virat Kohli for India

d <- teamBatsmenVsBowlersAllOppnAllMatchesRept(rcb_Allmatches,"Royal Challengers Bangalore",rank=1,dispRows=50)
d
## Source: local data frame [50 x 3]
## Groups: batsman [1]
## 
##    batsman          bowler  runs
##     (fctr)          (fctr) (dbl)
## 1  V Kohli        UT Yadav   129
## 2  V Kohli        R Ashwin   115
## 3  V Kohli        A Mishra   106
## 4  V Kohli       IK Pathan    92
## 5  V Kohli        DJ Bravo    79
## 6  V Kohli       RA Jadeja    78
## 7  V Kohli       JA Morkel    73
## 8  V Kohli       PP Chawla    64
## 9  V Kohli       SB Jakati    62
## 10 V Kohli Harbhajan Singh    61
## ..     ...             ...   ...
teamBatsmenVsBowlersAllOppnAllMatchesPlot(d)

batsmenVsBowler1-1

e <- teamBatsmenVsBowlersAllOppnAllMatchesPlot(d,plot=FALSE)
e
## Source: local data frame [50 x 3]
## Groups: batsman [1]
## 
##    batsman          bowler  runs
##     (fctr)          (fctr) (dbl)
## 1  V Kohli        UT Yadav   129
## 2  V Kohli        R Ashwin   115
## 3  V Kohli        A Mishra   106
## 4  V Kohli       IK Pathan    92
## 5  V Kohli        DJ Bravo    79
## 6  V Kohli       RA Jadeja    78
## 7  V Kohli       JA Morkel    73
## 8  V Kohli       PP Chawla    64
## 9  V Kohli       SB Jakati    62
## 10 V Kohli Harbhajan Singh    61
## ..     ...             ...   ...
# The following plot displays the performance of the Chennai Super Kings IPL T20 batsman (rank=2) against all opposition IPL bowlers. This is M S Dhoni for India
d <- teamBatsmenVsBowlersAllOppnAllMatchesRept(csk_Allmatches,"Chennai Super Kings",rank=2,dispRows=50)
teamBatsmenVsBowlersAllOppnAllMatchesPlot(d)

batsmenVsBowler1-2

# Best IPL T20 batsman of Delhi Daredevils against all other IPL  bowlers
d <- teamBatsmenVsBowlersAllOppnAllMatchesRept(dd_Allmatches,"Delhi Daredevils",rank=1,dispRows=30)
d
## Source: local data frame [30 x 3]
## Groups: batsman [1]
## 
##     batsman          bowler  runs
##      (fctr)          (fctr) (dbl)
## 1  V Sehwag        RP Singh    88
## 2  V Sehwag Harbhajan Singh    54
## 3  V Sehwag        MM Patel    52
## 4  V Sehwag       JA Morkel    47
## 5  V Sehwag   R Vinay Kumar    47
## 6  V Sehwag  AD Mascarenhas    47
## 7  V Sehwag         P Kumar    46
## 8  V Sehwag       PP Chawla    45
## 9  V Sehwag        R Sharma    43
## 10 V Sehwag         MS Gony    42
## ..      ...             ...   ...
teamBatsmenVsBowlersAllOppnAllMatchesPlot(d)

batsmenVsBowler1-3

# Best IPL T20 batsman of Deccan Chargers against all other IPL  bowlers
d <- teamBatsmenVsBowlersAllOppnAllMatchesRept(dc_Allmatches,"Deccan Chargers",rank=1,dispRows=30)
d
## Source: local data frame [30 x 3]
## Groups: batsman [1]
## 
##         batsman      bowler  runs
##          (fctr)      (fctr) (dbl)
## 1  AC Gilchrist     A Nehra    67
## 2  AC Gilchrist   DP Nannes    45
## 3  AC Gilchrist S Sreesanth    40
## 4  AC Gilchrist   JH Kallis    39
## 5  AC Gilchrist    MM Patel    39
## 6  AC Gilchrist   JA Morkel    34
## 7  AC Gilchrist   IK Pathan    34
## 8  AC Gilchrist    A Kumble    34
## 9  AC Gilchrist  AB Agarkar    31
## 10 AC Gilchrist    I Sharma    30
## ..          ...         ...   ...
teamBatsmenVsBowlersAllOppnAllMatchesPlot(d)

batsmenVsBowler1-4

14. Team bowling IPL T20 scorecard against all opposing IPL steams

The functions lists the top IPL T20 bowlers of each IPL team. This function returns a dataframe when ‘matches’ is the matches of the IPL and ‘theTeam’ is the same IPL team as in the functions below

teamBowlingScorecardAllOppnAllMatchesMain(matches=kkr_Allmatches,theTeam="Kolkata Knight Riders")
## Source: local data frame [52 x 5]
## 
##             bowler overs maidens  runs wickets
##             (fctr) (int)   (int) (dbl)   (dbl)
## 1        SP Narine    18       0  1289      84
## 2        JH Kallis    20       0  1105      46
## 3  Shakib Al Hasan    18       0   827      43
## 4         R Bhatia    15       0   905      38
## 5         L Balaji    21       0   879      37
## 6    Iqbal Abdulla    20       0   674      32
## 7         AB Dinda    17       0   605      29
## 8        PP Chawla    15       0   572      26
## 9         I Sharma    17       0   862      25
## 10        M Morkel    14       0   573      25
## ..             ...   ...     ...   ...     ...
teamBowlingScorecardAllOppnAllMatchesMain(matches=csk_Allmatches,theTeam="Chennai Super Kings")
## Source: local data frame [44 x 5]
## 
##            bowler overs maidens  runs wickets
##            (fctr) (int)   (int) (dbl)   (dbl)
## 1        R Ashwin    20       0  2127      98
## 2        DJ Bravo    17       0  1542      88
## 3       JA Morkel    20       0  2000      83
## 4       MM Sharma    19       0  1208      60
## 5       RA Jadeja    17       0  1346      58
## 6       SB Jakati    18       0  1154      46
## 7  M Muralitharan    16       0   977      41
## 8    DE Bollinger    13       0   662      41
## 9        L Balaji    21       0   809      35
## 10        A Nehra    12       0   591      33
## ..            ...   ...     ...   ...     ...
teamBowlingScorecardAllOppnAllMatchesMain(dc_Allmatches,"Deccan Chargers")
## Source: local data frame [43 x 5]
## 
##           bowler overs maidens  runs wickets
##           (fctr) (int)   (int) (dbl)   (dbl)
## 1        PP Ojha    18       0  1328      66
## 2       RP Singh    18       0  1229      57
## 3       A Mishra    14       0   735      32
## 4       DW Steyn    13       0   584      32
## 5      A Symonds    18       0   633      22
## 6     WPUJC Vaas     8       0   355      22
## 7      RJ Harris    15       0   463      21
## 8   DT Christian    17       0   583      20
## 9  Harmeet Singh    18       0   419      17
## 10     RG Sharma    13       0   339      15
## ..           ...   ...     ...   ...     ...
teamBowlingScorecardAllOppnAllMatchesMain(dd_Allmatches,"Delhi Daredevils")
## Source: local data frame [61 x 5]
## 
##         bowler overs maidens  runs wickets
##         (fctr) (int)   (int) (dbl)   (dbl)
## 1     A Mishra    20       0  1105      54
## 2     UT Yadav    19       0  1314      53
## 3     M Morkel    19       0  1113      52
## 4      A Nehra    16       0   758      41
## 5    IK Pathan    21       0  1191      34
## 6   PJ Sangwan    19       0   782      34
## 7    DP Nannes    17       0   596      31
## 8     S Nadeem    19       0  1046      30
## 9  MF Maharoof    18       0   507      29
## 10 Imran Tahir    13       0   485      26
## ..         ...   ...     ...   ...     ...
teamBowlingScorecardAllOppnAllMatchesMain(kxip_Allmatches,"Kings XI Punjab")
## Source: local data frame [52 x 5]
## 
##            bowler overs maidens  runs wickets
##            (fctr) (int)   (int) (dbl)   (dbl)
## 1       PP Chawla    15       0  2188      87
## 2       IK Pathan    18       0  1112      56
## 3         P Awana    21       0  1029      43
## 4         P Kumar    19       0  1152      35
## 5        AR Patel    19       0   797      33
## 6  Sandeep Sharma    14       0   704      32
## 7   Azhar Mahmood    18       0   659      30
## 8     S Sreesanth    18       0   750      28
## 9      MG Johnson    19       0   780      26
## 10      RJ Harris    15       0   584      26
## ..            ...   ...     ...   ...     ...
teamBowlingScorecardAllOppnAllMatchesMain(ktk_Allmatches,"Kochi Tuskers Kerala")
## Source: local data frame [13 x 5]
## 
##              bowler overs maidens  runs wickets
##              (fctr) (int)   (int) (dbl)   (dbl)
## 1     R Vinay Kumar    15       0   335      17
## 2          RP Singh    11       0   345      15
## 3         RA Jadeja    12       0   305       9
## 4          BJ Hodge     7       0    77       8
## 5       S Sreesanth     9       1   206       7
## 6          RV Gomez     7       0   124       5
## 7       NLTC Perera    10       0   111       5
## 8    P Parameswaran     9       0   137       4
## 9    M Muralitharan     5       0   141       2
## 10         RR Powar     7       0   112       2
## 11          B Akhil     2       0    22       0
## 12       P Prasanth     1       0    18       0
## 13 Y Gnaneswara Rao     1       0     7       0
teamBowlingScorecardAllOppnAllMatchesMain(mi_Allmatches,"Mumbai Indians")
## Source: local data frame [59 x 5]
## 
##             bowler overs maidens  runs wickets
##             (fctr) (int)   (int) (dbl)   (dbl)
## 1       SL Malinga    21       0  2478     158
## 2  Harbhajan Singh    20       0  2668     118
## 3       KA Pollard    16       0  1614      66
## 4         MM Patel    19       0   862      42
## 5      DS Kulkarni    19       0   825      37
## 6          PP Ojha    16       0   968      32
## 7         DJ Bravo    17       0   719      30
## 8           Z Khan    14       0   630      30
## 9       MG Johnson    11       0   436      22
## 10  MJ McClenaghan    12       0   386      18
## ..             ...   ...     ...   ...     ...
teamBowlingScorecardAllOppnAllMatchesMain(pw_Allmatches,"Pune Warriors")
## Source: local data frame [34 x 5]
## 
##          bowler overs maidens  runs wickets
##          (fctr) (int)   (int) (dbl)   (dbl)
## 1      R Sharma    17       0   854      35
## 2      AB Dinda    17       0   634      28
## 3       B Kumar    20       0   697      24
## 4    WD Parnell    16       1   444      21
## 5     AC Thomas    14       0   406      16
## 6  Yuvraj Singh    10       0   333      15
## 7      MR Marsh    13       0   281      14
## 8    AD Mathews    16       0   407      12
## 9       A Nehra    17       0   402      12
## 10   MN Samuels    14       0   250      10
## ..          ...   ...     ...   ...     ...
teamBowlingScorecardAllOppnAllMatchesMain(rcb_Allmatches,"Royal Challengers Bangalore")
## Source: local data frame [57 x 5]
## 
##           bowler overs maidens  runs wickets
##           (fctr) (int)   (int) (dbl)   (dbl)
## 1  R Vinay Kumar    21       0  1822      83
## 2         Z Khan    15       0  1237      53
## 3       A Kumble    18       0  1040      47
## 4       MA Starc    18       0   693      39
## 5        P Kumar    18       0  1078      37
## 6      YS Chahal    14       0   801      36
## 7       HV Patel    15       0   781      32
## 8       DW Steyn    15       0   654      32
## 9      S Aravind    11       0   548      32
## 10     JH Kallis    16       0  1088      26
## ..           ...   ...     ...   ...     ...
teamBowlingScorecardAllOppnAllMatchesMain(rr_Allmatches,"Rajasthan Royals")
## Source: local data frame [56 x 5]
## 
##           bowler overs maidens  runs wickets
##           (fctr) (int)   (int) (dbl)   (dbl)
## 1     SK Trivedi    19       0  1862      70
## 2      SR Watson    21       0  1633      68
## 3       SK Warne    16       0  1405      60
## 4    JP Faulkner    20       0  1224      49
## 5       MM Patel    20       0   779      39
## 6      KK Cooper    18       0   691      32
## 7        A Singh    14       0   620      31
## 8        SW Tait    19      NA    NA      26
## 9  Sohail Tanvir    12       0   266      24
## 10     YK Pathan    17       0   693      23
## ..           ...   ...     ...   ...     ...
teamBowlingScorecardAllOppnAllMatchesMain(sh_Allmatches,"Sunrisers Hyderabad")
## Source: local data frame [21 x 5]
## 
##          bowler overs maidens  runs wickets
##          (fctr) (int)   (int) (dbl)   (dbl)
## 1       B Kumar    16       0   761      40
## 2     KV Sharma    17       0   905      38
## 3      DW Steyn    17       0   968      33
## 4      A Mishra    16       0   726      29
## 5      I Sharma    18       0   704      20
## 6   NLTC Perera    13       0   453      19
## 7  MC Henriques    15       0   254      15
## 8     DJG Sammy    14       0   321      14
## 9      TA Boult    12       0   236      10
## 10    RS Bopara     7       0   160       8
## ..          ...   ...     ...   ...     ...

15. Team bowling IPL T20 scorecard against all opposing teams (continued)

The function lists the top bowlers of a IPL team (‘matches’) against the opposing teams

# Best Sunrisers Hyderabad bowlers in matches against CSK
teamBowlingScorecardAllOppnAllMatches(sh_Allmatches,'Chennai Super Kings')
## Source: local data frame [14 x 5]
## 
##            bowler overs maidens  runs wickets
##            (fctr) (int)   (int) (dbl)   (dbl)
## 1       KV Sharma    10       1   151       4
## 2         B Kumar     8       0   122       4
## 3        I Sharma     9       0   183       3
## 4        A Mishra     9       0    94       3
## 5     NLTC Perera     1       0    45       3
## 6        TA Boult     5       0    78       2
## 7  A Ashish Reddy     3       0    34       2
## 8       RS Bopara     1       0    29       2
## 9    MC Henriques     4       0    20       2
## 10       DW Steyn     7       0   125       1
## 11      DJG Sammy     4       0    75       0
## 12  Parvez Rasool     1       0    46       0
## 13      IK Pathan     1       0    34       0
## 14        P Kumar     4       0    33       0
# Best Kolkata Knight Riders bowlers in matches against Kings XI Punjab
teamBowlingScorecardAllOppnAllMatches(ktk_Allmatches,'Kings XI Punjab')
## Source: local data frame [7 x 5]
## 
##           bowler overs maidens  runs wickets
##           (fctr) (int)   (int) (dbl)   (dbl)
## 1       RP Singh     4       0    25       4
## 2    S Sreesanth     4       0    38       0
## 3  R Vinay Kumar     3       0    28       0
## 4      RA Jadeja     3       0    27       0
## 5       BJ Hodge     2       0    26       0
## 6 P Parameswaran     2       0    23       0
## 7       RV Gomez     1       0    12       0
# Best Mumbai Indian bowlers in matches against Delhi Daredevils
teamBowlingScorecardAllOppnAllMatches(mi_Allmatches,'Delhi Daredevils')
## Source: local data frame [37 x 5]
## 
##             bowler overs maidens  runs wickets
##             (fctr) (int)   (int) (dbl)   (dbl)
## 1       SL Malinga    14       0   271      21
## 2  Harbhajan Singh    17       1   318      17
## 3       KA Pollard    10       0   185       6
## 4       AG Murtaza     5       0    39       6
## 5      DS Kulkarni     9       0   116       5
## 6          A Nehra     6       0    55       4
## 7          PP Ojha    12       0   112       3
## 8    ST Jayasuriya     7       0    93       3
## 9         DJ Bravo     6       0    66       3
## 10      SM Pollock     4       0    49       3
## ..             ...   ...     ...   ...     ...
# Best Royal Challengers Bangalore bowlers in matches against Pune Warriors
teamBowlingScorecardAllOppnAllMatches(rcb_Allmatches,"Pune Warriors")
## Source: local data frame [16 x 5]
## 
##             bowler overs maidens  runs wickets
##             (fctr) (int)   (int) (dbl)   (dbl)
## 1    R Vinay Kumar    12       0   121      10
## 2           Z Khan     6       0    88       4
## 3         CH Gayle     3       0    18       4
## 4         M Kartik     6       0    54       3
## 5         HV Patel     5       0    65       2
## 6       DL Vettori     5       0    57       2
## 7   M Muralitharan     6       0    48       2
## 8         RP Singh     5       0    47       2
## 9     MC Henriques     4       0    44       2
## 10      JD Unadkat     4       0    37       2
## 11       R Rampaul     4       0    21       2
## 12      KP Appanna     5       0    53       1
## 13       S Aravind     4       0    35       1
## 14 J Syed Mohammad     2       0    26       1
## 15        A Mithun     4       0    26       0
## 16      TM Dilshan     1       0    24       0

16. Team Bowlers versus Batsmen (in T20 against all oppositions)

The functions below give the peformance of IPL bowlers versus opposing IPL batsman. They give the best bowlers and the total runs conceded and against whom were the runs conceded

# Best Chennai Super Kings IPL T20 bowlers overall  against all other IPL (rank=0)
teamBowlersVsBatsmenAllOppnAllMatchesMain(csk_Allmatches,theTeam="Chennai Super Kings",rank=0)
## Source: local data frame [10 x 2]
## 
##            bowler  runs
##            (fctr) (dbl)
## 1        R Ashwin  2063
## 2       JA Morkel  1917
## 3        DJ Bravo  1486
## 4       RA Jadeja  1320
## 5       MM Sharma  1192
## 6       SB Jakati  1134
## 7  M Muralitharan   928
## 8        SK Raina   888
## 9        L Balaji   781
## 10        MS Gony   654
# Top Chennai Super Kings IPL T20 bowler of India and runs conceded against different opposition batsmen 
(rank=1)
## [1] 1
m <-teamBowlersVsBatsmenAllOppnAllMatchesMain(csk_Allmatches,theTeam="Chennai Super Kings",rank=1)
m
## Source: local data frame [148 x 3]
## Groups: bowler [1]
## 
##      bowler      batsman runsConceded
##      (fctr)       (fctr)        (dbl)
## 1  R Ashwin      V Kohli          115
## 2  R Ashwin   GJ Maxwell           72
## 3  R Ashwin   RV Uthappa           68
## 4  R Ashwin    RG Sharma           59
## 5  R Ashwin    SR Watson           59
## 6  R Ashwin  LMP Simmons           58
## 7  R Ashwin     MS Bisla           52
## 8  R Ashwin     CH Gayle           49
## 9  R Ashwin    DA Warner           48
## 10 R Ashwin AC Gilchrist           46
## ..      ...          ...          ...
# Top Kolkata Knight Riders IPL T20 bowler and runs conceded  against different opposing IPL  batsmen (rank=1)
m <-teamBowlersVsBatsmenAllOppnAllMatchesMain(kkr_Allmatches,theTeam="Kolkata Knight Riders",rank=1)
m
## Source: local data frame [132 x 3]
## Groups: bowler [1]
## 
##       bowler    batsman runsConceded
##       (fctr)     (fctr)        (dbl)
## 1  SP Narine  RG Sharma           62
## 2  SP Narine   SK Raina           58
## 3  SP Narine    WP Saha           52
## 4  SP Narine  JP Duminy           50
## 5  SP Narine  DA Warner           44
## 6  SP Narine MEK Hussey           37
## 7  SP Narine  AM Rahane           33
## 8  SP Narine    V Kohli           29
## 9  SP Narine KD Karthik           27
## 10 SP Narine KA Pollard           26
## ..       ...        ...          ...
# Top IPL T20 bowlers versus batsmen of Delhi Daredevils(rank=0)
teamBowlersVsBatsmenAllOppnAllMatchesMain(dd_Allmatches,theTeam="Delhi Daredevils",rank=0)
## Source: local data frame [10 x 2]
## 
##         bowler  runs
##         (fctr) (dbl)
## 1     UT Yadav  1261
## 2    IK Pathan  1156
## 3     M Morkel  1075
## 4     A Mishra  1072
## 5     S Nadeem  1026
## 6   PJ Sangwan   744
## 7      A Nehra   728
## 8    DP Nannes   558
## 9  MF Maharoof   481
## 10 Imran Tahir   461

17. Team bowlers versus batsmen report (in IPL T20 matches against all opposing team)

#The best IPL T20 bowlers of other IPL teams against Chennai Super Kings
teamBowlersVsBatsmenAllOppnAllMatchesRept(matches=csk_Allmatches,theTeam="Chennai Super Kings",rank=0)
## Source: local data frame [10 x 2]
## 
##             bowler  runs
##             (fctr) (dbl)
## 1  Harbhajan Singh   461
## 2    R Vinay Kumar   435
## 3          P Kumar   421
## 4        PP Chawla   410
## 5        IK Pathan   399
## 6       SL Malinga   380
## 7         RP Singh   353
## 8        JH Kallis   348
## 9          PP Ojha   333
## 10       YK Pathan   293
# Best T20 performer against Mumbai Indians is A Mishra
a <- teamBowlersVsBatsmenAllOppnAllMatchesRept(mi_Allmatches,theTeam="Mumbai Indians",rank=1)
a
## Source: local data frame [24 x 3]
## Groups: bowler [1]
## 
##      bowler      batsman runsConceded
##      (fctr)       (fctr)        (dbl)
## 1  A Mishra   KA Pollard           91
## 2  A Mishra    AT Rayudu           71
## 3  A Mishra SR Tendulkar           55
## 4  A Mishra    RG Sharma           51
## 5  A Mishra    SS Tiwary           26
## 6  A Mishra    AM Rahane           23
## 7  A Mishra     DR Smith           16
## 8  A Mishra  LMP Simmons           16
## 9  A Mishra    JP Duminy           13
## 10 A Mishra     DJ Bravo           11
## ..      ...          ...          ...

18. Team bowlers versus batsmen report (in T20s against all opposing teams continued)

#Top Royal Challengers Bangalore T20 Indian bowlers against Rajasthan Royals
teamBowlersVsBatsmenAllOppnAllMatchesRept(matches=rcb_Allmatches,theTeam="Rajasthan Royals",rank=0)
## Source: local data frame [10 x 2]
## 
##           bowler  runs
##           (fctr) (dbl)
## 1  R Vinay Kumar   252
## 2         Z Khan   134
## 3        P Kumar   115
## 4       A Kumble   106
## 5      S Aravind   101
## 6       MA Starc   100
## 7      JH Kallis    96
## 8      YS Chahal    86
## 9       HV Patel    69
## 10      M Kartik    67
#Top Pune Warriors T20 Indian bowlers against Kings XI Punjab
teamBowlersVsBatsmenAllOppnAllMatchesRept(pw_Allmatches,"Kings XI Punjab",rank=0)
## Source: local data frame [10 x 2]
## 
##          bowler  runs
##          (fctr) (dbl)
## 1      R Sharma   128
## 2      AB Dinda    93
## 3       B Kumar    61
## 4    MN Samuels    50
## 5      MR Marsh    48
## 6      JD Ryder    43
## 7       A Nehra    42
## 8    BAW Mendis    38
## 9     LJ Wright    35
## 10 Yuvraj Singh    32

19. Team bowlers versus batsmen report (in T20s against all opposing teams) plot

This function can only be used for rank > 0 (rank=1,2,3..)

# Top IPL T20 bowler against Chennai Super Kings (This is Harbhajan Singh)
df <- teamBowlersVsBatsmenAllOppnAllMatchesRept(csk_Allmatches,theTeam="Chennai Super Kings",rank=1)
teamBowlersVsBatsmenAllOppnAllMatchesPlot(df,"Chennai Super Kings","Chennai Super Kings")

bowlerVsbatsmen1-1

# Top IPL T20 Indian bowler versus Delhi Daredevils (R Vinay Kumar)
df <- teamBowlersVsBatsmenAllOppnAllMatchesRept(dd_Allmatches,theTeam="Delhi Daredevils",rank=1)
teamBowlersVsBatsmenAllOppnAllMatchesPlot(df,"Delhi Daredevils","Delhi Daredevils")

bowlerVsbatsmen1-2

20. Team Bowler Wicket Kind in Twenty20 matches against all opposing IPL teams

# Top opposition IPL T20  bowlers against Chennai Super Kings and the kind of wickets
teamBowlingWicketKindAllOppnAllMatches(csk_Allmatches,t1="Chennai Super Kings",t2="All")

bowlingWicketkind1-1

# Top opposition IPL T20  bowlers against Royal Challengers Bangalore and the kind of 
# wickets. Get the data frame. Do not plot
m <-teamBowlingWicketKindAllOppnAllMatches(rcb_Allmatches,t1="Royal Challengers Bangalore",t2="All",plot=FALSE)
m
## Source: local data frame [34 x 3]
## Groups: bowler [?]
## 
##       bowler wicketKind     m
##       (fctr)      (chr) (int)
## 1   L Balaji     bowled     6
## 2   L Balaji     caught    10
## 3   L Balaji    run out     2
## 4  JA Morkel     bowled     4
## 5  JA Morkel     caught     6
## 6  JA Morkel        lbw     4
## 7    A Nehra     bowled     5
## 8    A Nehra     caught    14
## 9    A Nehra        lbw     1
## 10   A Nehra    run out     1
## ..       ...        ...   ...
# Top opposition IPL T20  bowlers against Delhi Daredevils and the kind of wickets
teamBowlingWicketKindAllOppnAllMatches(dd_Allmatches,t1="Delhi Daredevils",t2="All")

bowlingWicketkind1-2

21. Team Bowler Wicket Runs in IPL Twenty20 matches against all opposing teams

# Opposition T20 bowlers against Chennai Super Kings and runs conceded
teamBowlingWicketRunsAllOppnAllMatches(csk_Allmatches,t1="Chennai Super Kings",t2="All",plot=TRUE)

bowlingWicketRuns1-1

# Opposition T20 bowlers against Mumbai Indians and runs conceded returned as dataframe
m <-teamBowlingWicketRunsAllOppnAllMatches(mi_Allmatches,t1="Mumbai Indians",t2="All",plot=FALSE)
m
## Source: local data frame [10 x 3]
## 
##           bowler runsConceded wickets
##           (fctr)        (dbl)   (dbl)
## 1       DJ Bravo          299      24
## 2      PP Chawla          348      18
## 3        A Nehra          296      16
## 4       DW Steyn          326      16
## 5      IK Pathan          297      16
## 6      MM Sharma          293      15
## 7  R Vinay Kumar          402      15
## 8      SP Narine          193      14
## 9       RP Singh          182      13
## 10      AB Dinda          292      13
# Top T20 Indian bowlers against Kolkata Knight Riders and runs conceded
teamBowlingWicketRunsAllOppnAllMatches(kkr_Allmatches,t1="Kolkata Knight Riders",t2="All",plot=TRUE)

bowlingWicketRuns1-2

22. Team Bowler Wicket Runs in IPL Twenty20 matches against all opposing teams(continued)

#Top opposition IPL T20 bowlers against Sunrisers Hyderabad
teamBowlingWicketRunsAllOppnAllMatches(sh_Allmatches,t1="Sunrisers Hyderabad",t2="All",plot=TRUE)

bowlingWicketRuns2-1

#Top opposition IPL T20 bowlers against Pune Warriorss
teamBowlingWicketRunsAllOppnAllMatches(pw_Allmatches,t1="Pune Warriors",t2="All",plot=TRUE)

bowlingWicketRuns2-2bowlingWicketRuns2-3

#Top opposition IPL T20 bowlers against Kings XI Punjab
teamBowlingWicketRunsAllOppnAllMatches(kxip_Allmatches,t1="Kings XI Punjab",t2="All",plot=TRUE)

Conclusion

This post included all functions for an IPL team in all IPL T20 matches against all opposing IPL teams. As before the data frames for the IPL T20 matches are already available. You can load the data and begin to use them. If more insights from the dataframe are possible do go ahead. But please do attribute the source to Cricheet (http://cricsheet.org), my package yorkr and my blog. Do give the functions a spin for yourself.

The 4th and final part of the IPL yorkr package’s handling of IPL T20 will follow soon.

Watch this space!

You may also like

  1. Introducing cricket package yorkr-Part1:Beaten by sheer pace!.
  2. yorkr pads up for the Twenty20s: Part 1- Analyzing team“s match performance
  3. Literacy in India: A deepR dive
  4. Introducing cricketr! : An R package to analyze performances of cricketers
  5. Design principles of scalable distributed systems
  6. OpenCV: Fun with filters and convolution

yorkr crashes the IPL party! – Part 2


Most people say that it is the intellect which makes a great scientist. They are wrong: it is character.

                 Albert Einstein

*Science is organized knowledge. Wisdom is organized life.“*

                 Immanuel Kant

If I have seen further, it is by standing on the shoulders of giants

                 Isaac Newton
                 

Valid criticism does you a favor.

                 Carl Sagan

Introduction

In this post, my R package ‘yorkr’, continues to bat in the IPL Twenty20s. This post is a continuation of my earlier post – yorkr crashes the IPL party ! – Part 1. This post deals with Class 2 functions namely the performances of an IPL team in all T20 matches against another IPL team for e.g all T20 matches of Chennai Super Kings vs Royal Challengers Bangalore or Kochi Tuskers Kerala vs Mumbai Indians etc.

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

 

You can clone/fork the code for my package yorkr from Github at yorkr

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

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

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 IPL T20 matches between any 2 teams using the function below. The dir parameter should point to the folder which has the IPL T20 RData files of the individual matches. This function creates a data frame of all the IPL 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/IPL/IPL-T20-matches")
matches <- getAllMatchesBetweenTeams("Sunrisers Hyderabad","Royal Challengers Bangalore",dir=".")
dim(matches)
## [1] 1320   25

I have however already saved the IPL Twenty20 matches for all possible combinations of opposing IPL Teams. The data for these matches for the individual teams/countries can be obtained from Github at in the folder IPL-T20-allmatches-between-two-teams

Note: You will need to use the function below for future matches! The data in Cricsheet are from 2008 -2015

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 IPL Twenty20 matches between any 2 IPL teams into a single dataframe and save it in the current folder. The current implementation expects 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

# Available in yorkr_0.0.5. Can be installed from Github though!
#saveAllMatchesBetween2IPLTeams()

4. Load data directly for all matches between 2 IPL teams

As in my earlier post I pick all IPL Twenty20 matches between 2 random IPL 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 2 IPL teams
setwd("C:/software/cricket-package/york-test/yorkrData/IPL/IPL-T20-allmatches-between-two-teams")
load("Chennai Super Kings-Delhi Daredevils-allMatches.RData")
csk_dd_matches <- matches
load("Deccan Chargers-Kolkata Knight Riders-allMatches.RData")
dc_kkr_matches <- matches
load("Mumbai Indians-Pune Warriors-allMatches.RData")
mi_pw_matches <- matches
load("Rajasthan Royals-Sunrisers Hyderabad-allMatches.RData")
rr_sh_matches <- matches
load("Kings XI Punjab-Royal Challengers Bangalore-allMatches.RData")
kxip_rcb_matches <-matches
load("Chennai Super Kings-Kochi Tuskers Kerala-allMatches.RData")
csk_ktk_matches <-matches

5. Team Batsmen partnership in Twenty20 (all matches with opposing IPL team)

This function will create a report of the batting partnerships in the IPL teams for the matches between the teams. The report can be brief or detailed depending on the parameter ‘report’. As can be seen M S Dhoni tops the list for CSK, followed by Raina and then Murali Vijay for matches against Delhi Daredevils. For the Delhi Daredevils it is V Sehawag followed by Gambhir.

m<- teamBatsmenPartnershiOppnAllMatches(csk_dd_matches,'Chennai Super Kings',report="summary")
m
## Source: local data frame [29 x 2]
## 
##         batsman totalRuns
##          (fctr)     (dbl)
## 1      MS Dhoni       364
## 2      SK Raina       335
## 3       M Vijay       290
## 4   S Badrinath       185
## 5     ML Hayden       181
## 6    MEK Hussey       169
## 7  F du Plessis       100
## 8      S Vidyut        94
## 9      DR Smith        81
## 10    JA Morkel        80
## ..          ...       ...
m<- teamBatsmenPartnershiOppnAllMatches(csk_dd_matches,'Delhi Daredevils',report="summary")
m
## Source: local data frame [53 x 2]
## 
##             batsman totalRuns
##              (fctr)     (dbl)
## 1          V Sehwag       233
## 2         G Gambhir       200
## 3         DA Warner       134
## 4    AB de Villiers       133
## 5        KD Karthik       129
## 6  DPMD Jayawardene        89
## 7         JA Morkel        81
## 8        TM Dilshan        79
## 9          S Dhawan        78
## 10          SS Iyer        77
## ..              ...       ...
m <-teamBatsmenPartnershiOppnAllMatches(dc_kkr_matches,'Deccan Chargers',report="summary")
m
## Source: local data frame [29 x 2]
## 
##            batsman totalRuns
##             (fctr)     (dbl)
## 1     AC Gilchrist       166
## 2         HH Gibbs       145
## 3        RG Sharma       116
## 4         S Dhawan       111
## 5        A Symonds       100
## 6  Y Venugopal Rao        92
## 7         B Chipli        60
## 8     DB Ravi Teja        54
## 9         TL Suman        53
## 10      VVS Laxman        32
## ..             ...       ...
m <-teamBatsmenPartnershiOppnAllMatches(mi_pw_matches,'Mumbai Indians',report="detailed")
m[1:30,]
##         batsman   nonStriker partnershipRuns totalRuns
## 1  SR Tendulkar JEC Franklin              24       152
## 2  SR Tendulkar    AT Rayudu              46       152
## 3  SR Tendulkar    RG Sharma               2       152
## 4  SR Tendulkar   KD Karthik              20       152
## 5  SR Tendulkar   RT Ponting              39       152
## 6  SR Tendulkar  AC Blizzard              12       152
## 7  SR Tendulkar  RJ Peterson               9       152
## 8     RG Sharma SR Tendulkar               3       135
## 9     RG Sharma JEC Franklin               0       135
## 10    RG Sharma    AT Rayudu              34       135
## 11    RG Sharma    A Symonds              19       135
## 12    RG Sharma   KD Karthik              19       135
## 13    RG Sharma   KA Pollard              47       135
## 14    RG Sharma     TL Suman               7       135
## 15    RG Sharma   GJ Maxwell               6       135
## 16   KD Karthik SR Tendulkar               8       108
## 17   KD Karthik JEC Franklin              32       108
## 18   KD Karthik    AT Rayudu               3       108
## 19   KD Karthik    RG Sharma              50       108
## 20   KD Karthik   SL Malinga              10       108
## 21   KD Karthik      PP Ojha               0       108
## 22   KD Karthik  RJ Peterson               4       108
## 23   KD Karthik  NLTC Perera               1       108
## 24    AT Rayudu SR Tendulkar              54        92
## 25    AT Rayudu    RG Sharma              37        92
## 26    AT Rayudu   KD Karthik               1        92
## 27 JEC Franklin SR Tendulkar              31        63
## 28 JEC Franklin    RG Sharma               1        63
## 29 JEC Franklin   KD Karthik              15        63
## 30 JEC Franklin     SA Yadav              10        63
m <-teamBatsmenPartnershiOppnAllMatches(rr_sh_matches,'Sunrisers Hyderabad',report="summary")
m
## Source: local data frame [23 x 2]
## 
##         batsman totalRuns
##          (fctr)     (dbl)
## 1      S Dhawan       168
## 2     DJG Sammy        95
## 3    EJG Morgan        90
## 4     DA Warner        83
## 5       NV Ojha        50
## 6      KL Rahul        40
## 7     RS Bopara        40
## 8      DW Steyn        31
## 9      CL White        31
## 10 MC Henriques        29
## ..          ...       ...
m <-teamBatsmenPartnershiOppnAllMatches(kxip_rcb_matches,'Kings XI Punjab',report="summary")
m
## Source: local data frame [47 x 2]
## 
##          batsman totalRuns
##           (fctr)     (dbl)
## 1       SE Marsh       246
## 2      DA Miller       224
## 3      RS Bopara       203
## 4   AC Gilchrist       191
## 5   Yuvraj Singh       126
## 6       MS Bisla       103
## 7  Mandeep Singh       100
## 8      DJ Hussey        99
## 9  Azhar Mahmood        96
## 10 KC Sangakkara        88
## ..           ...       ...
m <-teamBatsmenPartnershiOppnAllMatches(csk_ktk_matches,'Kochi Tuskers Kerala',report="summary")
m
## Source: local data frame [8 x 2]
## 
##            batsman totalRuns
##             (fctr)     (dbl)
## 1      BB McCullum        80
## 2         BJ Hodge        70
## 3         PA Patel        40
## 4        RA Jadeja        35
## 5 Y Gnaneswara Rao        19
## 6 DPMD Jayawardene        16
## 7          OA Shah         3
## 8        KM Jadhav         1

6. Team batsmen partnership in Twenty20 (all matches with opposing IPL team)

This is plotted graphically in the charts below. The partnerships are shown. Note: All functions which create a plot also include a parameter plot=TRUE/FALSE. If you set this as FALSE then a data frame is returned. You can use the dataframe to create an interactive plot for the partnerships (mouse over) using packages like plotly,rcharts, googleVis or ggvis.

teamBatsmenPartnershipOppnAllMatchesChart(csk_dd_matches,'Chennai Super Kings',"Delhi Daredevils")

teamBatsmenPartnership-1

teamBatsmenPartnershipOppnAllMatchesChart(dc_kkr_matches,main="Kolkata Knight Riders",opposition="Deccan Chargers")

teamBatsmenPartnership-2

teamBatsmenPartnershipOppnAllMatchesChart(kxip_rcb_matches,"Royal Challengers Bangalore",opposition="Kings XI Punjab")

teamBatsmenPartnership-3

teamBatsmenPartnershipOppnAllMatchesChart(mi_pw_matches,"Mumbai Indians","Pune Warriors")

teamBatsmenPartnership-4

m <- teamBatsmenPartnershipOppnAllMatchesChart(rr_sh_matches,"Rajasthan Royals","Sunrisers Hyderabad",plot=FALSE)
m[1:30,]
##        batsman  nonStriker runs
## 1    SR Watson   STR Binny   60
## 2    AM Rahane   STR Binny   59
## 3    STR Binny   AM Rahane   45
## 4    SR Watson    R Dravid   42
## 5    AM Rahane   SV Samson   41
## 6     BJ Hodge   SV Samson   36
## 7    CH Morris   STR Binny   34
## 8    AM Rahane   SR Watson   31
## 9     R Dravid   SR Watson   30
## 10   SV Samson   AM Rahane   29
## 11   SR Watson   AM Rahane   27
## 12   SPD Smith    DJ Hooda   25
## 13   SPD Smith JP Faulkner   24
## 14   SPD Smith   STR Binny   20
## 15    R Dravid   AM Rahane   18
## 16    BJ Hodge JP Faulkner   18
## 17 JP Faulkner   SPD Smith   18
## 18   SV Samson     KK Nair   14
## 19 JP Faulkner   STR Binny   14
## 20   SV Samson   STR Binny   13
## 21   SPD Smith   AM Rahane   13
## 22   SR Watson   SPD Smith   12
## 23   STR Binny JP Faulkner   12
## 24   STR Binny   SPD Smith   12
## 25 JP Faulkner   SV Samson   12
## 26     KK Nair   SV Samson   12
## 27 JP Faulkner    BJ Hodge   11
## 28   SPD Smith   SR Watson   10
## 29   STR Binny   SR Watson    9
## 30   SV Samson    BJ Hodge    9

7. Team batsmen versus bowler in Twenty20 (all matches with opposing IPL team)

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

# Adam Gilchrist was the top performer for Deccan Chargers
teamBatsmenVsBowlersOppnAllMatches(dc_kkr_matches,"Deccan Chargers","Kolkata Knight Riders")

batsmenvsBowler-1

teamBatsmenVsBowlersOppnAllMatches(csk_dd_matches,"Delhi Daredevils","Chennai Super Kings",top=3)

batsmenvsBowler-2

m <- teamBatsmenVsBowlersOppnAllMatches(csk_ktk_matches,"Chennai Super Kings","Kochi Tuskers Kerala",top=10,plot=FALSE)
m
## Source: local data frame [37 x 3]
## Groups: batsman [1]
## 
##     batsman         bowler  runs
##      (fctr)         (fctr) (dbl)
## 1  SK Raina       RP Singh     6
## 2  SK Raina    S Sreesanth    18
## 3  SK Raina M Muralitharan     1
## 4  SK Raina  R Vinay Kumar     4
## 5  SK Raina    NLTC Perera    11
## 6  SK Raina       RR Powar    13
## 7  SK Raina       RV Gomez    16
## 8   WP Saha       RP Singh    15
## 9   WP Saha M Muralitharan    11
## 10  WP Saha       BJ Hodge     1
## ..      ...            ...   ...
teamBatsmenVsBowlersOppnAllMatches(rr_sh_matches,"Sunrisers Hyderabad","Rajasthan Royals")

batsmenvsBowler-3

8. Team batsmen versus bowler in Twenty20(all matches with opposing IPL team)

The following tables gives the overall performances of the IPL team’s batsmen against the opposition.

#Chris Gayle followed by Virat Kohli tops for RCB
a <-teamBattingScorecardOppnAllMatches(kxip_rcb_matches,main="Royal Challengers Bangalore",opposition="Kings XI Punjab")
## Total= 2444
a
## Source: local data frame [55 x 5]
## 
##           batsman ballsPlayed fours sixes  runs
##            (fctr)       (int) (int) (int) (dbl)
## 1        CH Gayle         313    45    41   561
## 2         V Kohli         296    39     8   344
## 3  AB de Villiers         183    23    16   301
## 4       JH Kallis         133    18     7   187
## 5        R Dravid          90    11     1   105
## 6      RV Uthappa          47     7     6    92
## 7       CA Pujara          66    11    NA    70
## 8       MK Pandey          50     5     3    67
## 9    KP Pietersen          43     7     1    66
## 10     MV Boucher          36     4     1    41
## ..            ...         ...   ...   ...   ...
#Tendulkar & Rohit Sharma lead for Mumbai Indians
teamBattingScorecardOppnAllMatches(mi_pw_matches,"Mumbai Indians","Pune Warriors")
## Total= 756
## Source: local data frame [20 x 5]
## 
##            batsman ballsPlayed fours sixes  runs
##             (fctr)       (int) (int) (int) (dbl)
## 1     SR Tendulkar         134    21     1   152
## 2        RG Sharma         121     7     6   135
## 3       KD Karthik         107    10     3   108
## 4        AT Rayudu          93     8     1    92
## 5     JEC Franklin          70     5     2    63
## 6       KA Pollard          43     3     3    55
## 7         TL Suman          16     3     3    36
## 8  Harbhajan Singh          22     3     1    29
## 9       SL Malinga          16     2     1    19
## 10       A Symonds          18     2    NA    19
## 11      RT Ponting          17     2    NA    14
## 12      GJ Maxwell           7     1     1    13
## 13     RJ Peterson          13     1    NA    13
## 14     AC Blizzard           6     1    NA     6
## 15         PP Ojha           2    NA    NA     1
## 16        MM Patel           2    NA    NA     1
## 17         RE Levi           2    NA    NA     0
## 18        SA Yadav           4    NA    NA     0
## 19     NLTC Perera           4    NA    NA     0
## 20        DR Smith           1    NA    NA     0
teamBattingScorecardOppnAllMatches(mi_pw_matches,"Pune Warriors","Mumbai Indians")
## Total= 714
## Source: local data frame [28 x 5]
## 
##         batsman ballsPlayed fours sixes  runs
##          (fctr)       (int) (int) (int) (dbl)
## 1    RV Uthappa         131    13     4   151
## 2     MK Pandey          80     5     4    88
## 3  Yuvraj Singh          62     3     6    77
## 4      M Manhas          36     5    NA    42
## 5     SPD Smith          38     4    NA    41
## 6      MR Marsh          26     2     2    38
## 7      M Kartik          21     2     1    25
## 8      R Sharma          22     2     1    23
## 9      TL Suman          15     5    NA    23
## 10   WD Parnell          24     3    NA    22
## ..          ...         ...   ...   ...   ...
teamBattingScorecardOppnAllMatches(csk_dd_matches,"Delhi Daredevils","Chennai Super Kings")
## Total= 1983
## Source: local data frame [53 x 5]
## 
##             batsman ballsPlayed fours sixes  runs
##              (fctr)       (int) (int) (int) (dbl)
## 1          V Sehwag         147    27     9   233
## 2         G Gambhir         155    23     2   200
## 3         DA Warner         130    11     2   134
## 4    AB de Villiers          80     7     6   133
## 5        KD Karthik          99    15     1   129
## 6  DPMD Jayawardene          77     7     2    89
## 7         JA Morkel          63     8     2    81
## 8        TM Dilshan          65     8     3    79
## 9          S Dhawan          58     8     2    78
## 10          SS Iyer          56    11     1    77
## ..              ...         ...   ...   ...   ...
teamBattingScorecardOppnAllMatches(rr_sh_matches,"Rajasthan Royals","Sunrisers Hyderabad")
## Total= 808
## Source: local data frame [17 x 5]
## 
##          batsman ballsPlayed fours sixes  runs
##           (fctr)       (int) (int) (int) (dbl)
## 1      SR Watson          97    22     4   148
## 2      AM Rahane         145    17     1   148
## 3      SPD Smith          81    11     2   103
## 4      STR Binny          83     6     1    90
## 5      SV Samson          83     3     4    76
## 6    JP Faulkner          41     7     2    59
## 7       BJ Hodge          37     2     5    55
## 8       R Dravid          44     7     1    48
## 9      CH Morris          11     2     3    34
## 10       KK Nair          23     3    NA    17
## 11      R Bhatia          10     1    NA     8
## 12   DS Kulkarni           6     1    NA     7
## 13      DJ Hooda           9    NA    NA     7
## 14      AM Nayar           3     1    NA     4
## 15      PV Tambe           7    NA    NA     3
## 16 KW Richardson           2    NA    NA     1
## 17     DH Yagnik           4    NA    NA     0

9. Team performances of IPL bowlers (all matches with opposing IPL team)

Like the function above the following tables provide the top IPL bowlers of the respective teams in the matches against the opposition.

#Piyush Chawla has the most wickets for KXIP against RCB
teamBowlingPerfOppnAllMatches(kxip_rcb_matches,"Kings XI Punjab","Royal Challengers Bangalore")
## Source: local data frame [38 x 5]
## 
##            bowler overs maidens  runs wickets
##            (fctr) (int)   (int) (dbl)   (dbl)
## 1       PP Chawla    14       0   311      12
## 2       IK Pathan    12       0   159       9
## 3      YA Abdulla     9       1   103       8
## 4       RJ Harris     5       0    87       7
## 5         P Awana    11       0   149       6
## 6     S Sreesanth     6       0   101       5
## 7   Azhar Mahmood     8       0    74       5
## 8  Sandeep Sharma     8       1   101       4
## 9        AR Patel     5       0    94       4
## 10      VRV Singh     6       0    70       4
## ..            ...   ...     ...   ...     ...
#Ashwin is the highest wicket takes for CSK against DD
teamBowlingPerfOppnAllMatches(csk_dd_matches,main="Chennai Super Kings",opposition="Delhi Daredevils")
## Source: local data frame [26 x 5]
## 
##           bowler overs maidens  runs wickets
##           (fctr) (int)   (int) (dbl)   (dbl)
## 1       R Ashwin     9       0   233      17
## 2      JA Morkel    11       0   338      10
## 3       DJ Bravo     5       0   135       8
## 4      SB Jakati     4       0   140       6
## 5       L Balaji    10       0   117       6
## 6      MM Sharma     1       0    99       6
## 7      RA Jadeja     2       0    85       4
## 8      IC Pandey     1       0    80       4
## 9  BW Hilfenhaus     5       0    53       4
## 10       A Nehra     1       0    25       4
## ..           ...   ...     ...   ...     ...
teamBowlingPerfOppnAllMatches(dc_kkr_matches,"Deccan Chargers","Kolkata Knight Riders")
## Source: local data frame [26 x 5]
## 
##            bowler overs maidens  runs wickets
##            (fctr) (int)   (int) (dbl)   (dbl)
## 1        RP Singh    11       0   161       7
## 2         PP Ojha    11       0   196       6
## 3      WPUJC Vaas     4       0    67       5
## 4       A Symonds    12       0   100       4
## 5        DW Steyn     8       0    88       4
## 6        A Mishra     8       0    68       3
## 7  Jaskaran Singh     6       0    53       3
## 8       SB Styris     7       0    79       2
## 9       RJ Harris     4       0    20       2
## 10  Harmeet Singh    10       0    84       1
## ..            ...   ...     ...   ...     ...

10. Team bowler’s wickets in IPL Twenty20 (all matches with opposing IPL team)

This provided a graphical plot of the tables above

# Dirk Nannes and Umesh Yadav top for DD against CSK
teamBowlersWicketsOppnAllMatches(csk_dd_matches,"Delhi Daredevils","Chennai Superkings")

bowlerWicketsOppn-1

# SL Malinga and Munaf Patel lead in MI vs PW clashes
teamBowlersWicketsOppnAllMatches(mi_pw_matches,"Mumbai Indians","Pune Warrors")

bowlerWicketsOppn-2

teamBowlersWicketsOppnAllMatches(dc_kkr_matches,"Kolkata Knight Riders","Deccan Chargers",top=10) 

bowlerWicketsOppn-3

m <-teamBowlersWicketsOppnAllMatches(kxip_rcb_matches,"Royal Challengers Bangalore","Kings XI Punjab",plot=FALSE)
m
## Source: local data frame [20 x 2]
## 
##              bowler wickets
##              (fctr)   (int)
## 1         S Aravind       8
## 2            Z Khan       7
## 3          MA Starc       7
## 4          HV Patel       6
## 5           P Kumar       5
## 6         YS Chahal       5
## 7         JH Kallis       4
## 8     R Vinay Kumar       3
## 9          A Kumble       3
## 10         CH Gayle       3
## 11      AB McDonald       3
## 12         VR Aaron       3
## 13         DW Steyn       2
## 14    CK Langeveldt       2
## 15       DL Vettori       2
## 16         M Kartik       2
## 17 RE van der Merwe       2
## 18        R Rampaul       1
## 19        JA Morkel       1
## 20         AB Dinda       1

11. Team bowler vs batsmen in Twenty20(all matches with opposing IPL team)

These plots show how the IPL bowlers fared against the batsmen. It shows which of the opposing IPL teams batsmen were able to score the most runs

teamBowlersVsBatsmenOppnAllMatches(rr_sh_matches,'Rajasthan Royals',"Sunrisers Hyderabd",top=5)

bowlerVsBatsmen-1

teamBowlersVsBatsmenOppnAllMatches(kxip_rcb_matches,"Kings XI Punjab","Royal Challengers Bangalore",top=3)

bowlerVsBatsmen-2

teamBowlersVsBatsmenOppnAllMatches(dc_kkr_matches,"Deccan Chargers","Kolkata Knight Riders")

bowlerVsBatsmen-3

12. Team bowler’s wicket kind in Twenty20(caught,bowled,etc) (all matches with opposing IPL team)

The charts below show the wicket kind taken by the bowler of the IPL team(caught, bowled, lbw etc)

teamBowlersWicketKindOppnAllMatches(csk_dd_matches,"Delhi Daredevils","Chennai Super Kings",plot=TRUE)

bowlerWickets-1

m <- teamBowlersWicketKindOppnAllMatches(mi_pw_matches,"Pune Warriors","Mumbai Indians",plot=FALSE)
m[1:30,]
##          bowler wicketKind wicketPlayerOut runs
## 1       SB Wagh     caught    JEC Franklin   31
## 2      R Sharma     caught    SR Tendulkar   64
## 3     AC Thomas     caught       AT Rayudu   69
## 4      M Kartik    stumped         RE Levi   70
## 5      AB Dinda     caught       AT Rayudu  150
## 6      AB Dinda     caught       RG Sharma  150
## 7      M Kartik    stumped      KD Karthik   70
## 8    MN Samuels     bowled        SA Yadav   21
## 9      R Sharma     bowled      KA Pollard   64
## 10     AB Dinda     caught    JEC Franklin  150
## 11   WD Parnell     caught      SL Malinga   64
## 12     AB Dinda        lbw Harbhajan Singh  150
## 13 Yuvraj Singh     caught      RT Ponting   61
## 14     AJ Finch     caught    SR Tendulkar   11
## 15     MR Marsh        lbw      KD Karthik   24
## 16    AC Thomas     caught     AC Blizzard   69
## 17 Yuvraj Singh     caught    SR Tendulkar   61
## 18 Yuvraj Singh     caught       AT Rayudu   61
## 19     R Sharma     caught       RG Sharma   64
## 20     R Sharma     caught        TL Suman   64
## 21    JE Taylor     caught       A Symonds   34
## 22    JE Taylor     caught      KA Pollard   34
## 23      B Kumar     caught    JEC Franklin   50
## 24    MJ Clarke    run out       RG Sharma    9
## 25      A Nehra     caught    SR Tendulkar   19
## 26      A Nehra     caught     RJ Peterson   19
## 27      B Kumar     bowled       AT Rayudu   50
## 28      A Nehra    run out     NLTC Perera   19
## 29     AB Dinda     caught Harbhajan Singh  150
## 30   WD Parnell    run out      SL Malinga   64
teamBowlersWicketKindOppnAllMatches(dc_kkr_matches,"Kolkata Knight Riders",'Deccan Chargers',plot=TRUE)

bowlerWickets-2

13. Team bowler’s wicket taken and runs conceded in Twenty20(all matches with opposing IPL team)

teamBowlersWicketRunsOppnAllMatches(csk_ktk_matches,"Kochi Tuskers Kerala","Chennai Super Kings")

wicketRuns-1

m <-teamBowlersWicketRunsOppnAllMatches(mi_pw_matches,"Mumbai Indians","Pune Warriors",plot=FALSE)
m[1:30,]
## Source: local data frame [30 x 5]
## 
##             bowler overs maidens  runs wickets
##             (fctr) (int)   (int) (dbl)   (dbl)
## 1       AG Murtaza     4       0    18       2
## 2       SL Malinga     9       1   143      10
## 3         AN Ahmed     5       0    40       4
## 4         MM Patel     6       1    88       7
## 5       KA Pollard     6       0    99       5
## 6     JEC Franklin     4       0    64       1
## 7  Harbhajan Singh     7       0    85       6
## 8          PP Ojha     8       0    95       4
## 9       MG Johnson     5       0    41       4
## 10        R Dhawan     1       0    27       0
## ..             ...   ...     ...   ...     ...

14. Plot of wins vs losses between teams in IPL T20 confrontations

setwd("C:/software/cricket-package/york-test/yorkrData/IPL/IPL-T20-matches")
plotWinLossBetweenTeams("Chennai Super Kings","Delhi Daredevils")

winsLosses-1

plotWinLossBetweenTeams("Deccan Chargers","Kolkata Knight Riders",".")

winsLosses-2

plotWinLossBetweenTeams('Kings XI Punjab',"Royal Challengers Bangalore",".")

winsLosses-3

plotWinLossBetweenTeams("Mumbai Indians","Pune Warriors",".")

winsLosses-4

plotWinLossBetweenTeams('Rajasthan Royals',"Sunrisers Hyderabad",".")

winsLosses-5

plotWinLossBetweenTeams('Chennai Super Kings',"Mumbai Indians",".")

winsLosses-6

Conclusion

This post included all functions for all IPL Twenty20 matches between any 2 IPL teams. As before the data frames are already available. You can load the data and begin to use them. If more insights from the dataframe are possible do go ahead. But please do attribute the source to Cricheet (http://cricsheet.org), my package yorkr and my blog. Do give the functions a spin for yourself!

You may also like

  1. yorkr pads up for the Twenty20s: Part 1- Analyzing team“s match performance
  2. yorkr pads up for the Twenty20s:Part 4- Individual batting and bowling performances
  3. Introducing cricket package yorkr: Part 2-Trapped leg before wicket!
  4. Introducing cricket package yorkr:Part 4-In the block hole!
  5. Introducing cricketr! : An R package to analyze performances of cricketers
  6. Cricket analytics with cricketr
  7. OpenCV: Fun with filters and convolution
  8. To Hadoop, or not to Hadoop
  9. Close encounters with the future
  10. Presentation on ‘Evolution to LTE’