library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(magrittr) # Load the magrittr package
library(ggplot2)

# Load IPL deliveries dataset (assuming it has the necessary columns)
deliveries <- read.csv("deliveries.csv")

# Group by match ID and innings (assuming innings information is in the 'inning' column)
bowlers_by_innings <- deliveries %>%
  group_by(match_id, inning) %>% 
  summarise(bowler_count = n_distinct(bowler))
## `summarise()` regrouping output by 'match_id' (override with `.groups` argument)
# Find the innings with the maximum number of bowlers
max_bowlers_innings <- bowlers_by_innings %>%
  filter(bowler_count == max(bowler_count))

# Extract bowling statistics for the max bowlers innings
max_bowlers_stats <- deliveries %>%
  filter(match_id == max_bowlers_innings$match_id[1] & inning == max_bowlers_innings$inning[1]) %>%
  group_by(bowler) %>%
  summarise(runs_conceded = sum(total_runs), 
            wickets_taken = sum(player_dismissed == 1),
            overs = sum(over) + sum(ball) / 6,  # Calculate overs based on over and ball columns
            economy = runs_conceded / overs)
## `summarise()` ungrouping output (override with `.groups` argument)
# Print the results
cat("Team with maximum bowlers in an innings:", max_bowlers_innings$match_id[1], "Inn:", max_bowlers_innings$inning[1], "\n")
## Team with maximum bowlers in an innings: 1 Inn: 1
print(max_bowlers_stats)
## # A tibble: 7 x 5
##   bowler      runs_conceded wickets_taken overs economy
##   <chr>               <int>         <int> <dbl>   <dbl>
## 1 A Choudhary            55             0 328.   0.168 
## 2 S Aravind              36             0 202.   0.178 
## 3 SR Watson              41             0 250.   0.164 
## 4 STR Binny              10             0  69.5  0.144 
## 5 TM Head                11             0  51.5  0.214 
## 6 TS Mills               32             0 256.   0.125 
## 7 YS Chahal              22             0 230    0.0957