With the Cricket World Cup going on, I wanted to create a Duckworth-Lewis calculator of my own for One Day Internationals using R.
This is a challenge I assigned myself, to push myself in understanding more on R, and what I could do. Duckworth-Lewis is an algorithm used in cricket when unexpected delays (notably bad weather) takes centre stage. The algorithm (in One Day Internationals) involves calculating Team 2's Par Score, which is where 'Team 2 Target' equals 'Team 1 Score' times the quotient of 'Team 2 Resources' and 'Team 1 Resources', and we add 1 to find the target (otherwise it creates room for a South Africa 2003 World Cup scenario).
team2_target = function(team1_score, team1_resources, team2_resources) {
return((team1_score * (team2_resources/team1_resources) + 1)
}
I want to make my function use the number of wickets lost, as well as the overs remaining to calculate the 'Team 2 Resources' variable. For example, if Team 1 scored 277 out of its full 50 overs and Team 2 scored 240, with the loss of 4 wickets after 40 overs, I want to be able to use the 'Overs' and 'Wickets Lost' as variables. It sounds really simple, but both these factors matter, and if either of my desired variables change, the team2_resources variable itself will change