Problem 56528. Cricket - Most Frequent Bowler-Batter Wicket Combinations

Given a table representing all wickets taken in a particular set of matches, return a table of the bowler-batter pairs that occur most commonly.
The input table will have three variables: Batter, Bowler, and Dismissal, representing the batter dismissed, the bowler of the delivery when the wicket fell, and the type of dismissal, respectively. The dismissal will be one of the set: "bowled", "caught", "caught and bowled", "hit wicket", "lbw", "run out", "stumped". Note that run outs are included in the list of wickets. However, because they are not credited to the bowler, your function should not count these.
The output table should have three variables: Batter, Bowler, and NumberOfDismissals. Each row of the table should represent a unique combination of bowler and batter, all with the same value of NumberOfDismissals (which should be the maximum of all pairs in the data set).
For example,
A table of 8 dismissals, giving batter name, bowler name, and type of dismissal. One entry is crossed out, because the dismissal is "run out". This table is aggregated into a square matrix of batters (rows) vs bowlers (columns). Each entry in the matrix is the number of times each batter-bowler pair appears in the original table. The maximum value in the matrix is highlighted, one from the row "Ben" and the other from the row "Renee", both from the column "Ned". This matrix is then transformed to the resulting table of batter-bowler combinations (Ben-Ned and Renee-Ned), both with NumberOfDismissals equal to 2.
bt = ["Ben";"Matt";"Renee";"Renee";"Ben";"Ned";"Ben";"Renee"];
bw = ["Ned";"Renee";"Ned";"Ben";"Ned";"Matt";"Renee";"Ned"];
w = ["hit wicket";"lbw";"bowled";"caught";"lbw";"stumped";"run out";"caught"];
wickets = table(bt,bw,w,'VariableNames',["Batter","Bowler","Dismissal"])
wickets =
8×3 table
Batter Bowler Dismissal
_______ _______ ____________
"Ben" "Ned" "hit wicket"
"Matt" "Renee" "lbw"
"Renee" "Ned" "bowled"
"Renee" "Ben" "caught"
"Ben" "Ned" "lbw"
"Ned" "Matt" "stumped"
"Ben" "Renee" "run out"
"Renee" "Ned" "caught"
pairs = whosyourbunny(wickets)
pairs =
2×3 table
Batter Bowler NumberOfDismissals
_______ ______ __________________
"Ben" "Ned" 2
"Renee" "Ned" 2

Solution Stats

69.7% Correct | 30.3% Incorrect
Last Solution submitted on Nov 03, 2023

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers18

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!