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
# Load IPL deliveries and matches datasets
deliveries <- read.csv("deliveries.csv")
matches <- read.csv("matches.csv")
# Calculate dot balls for each toss winner
dot_balls_by_toss_winner <- deliveries %>%
group_by(match_id, batting_team) %>%
summarise(dot_balls = sum(is.na(batsman_runs) | batsman_runs == 0)) %>%
inner_join(matches, by = c("match_id" = "id")) %>%
group_by(toss_winner) %>%
summarise(total_dot_balls = sum(dot_balls), match_id = first(match_id)) # Keep the first match_id
## `summarise()` regrouping output by 'match_id' (override with `.groups` argument)
## `summarise()` ungrouping output (override with `.groups` argument)
# Find the toss winner with maximum dot balls
max_dot_balls_winner <- dot_balls_by_toss_winner %>%
filter(total_dot_balls == max(total_dot_balls))
# Find the match details
max_dot_balls_match <- matches %>%
filter(id == max_dot_balls_winner$match_id)
# Print the results
cat("Toss-winning team with maximum dot balls:", max_dot_balls_winner$toss_winner, "\n")
## Toss-winning team with maximum dot balls: Mumbai Indians
cat("Match number:", max_dot_balls_match$id, "\n")
## Match number: 7
cat("Opponent team:", max_dot_balls_match$team2, "\n")
## Opponent team: Mumbai Indians