matches <- read.csv(“matches.csv”) deliveris <- read.csv(“deliveries.csv”) deliveries\(batting_team <- gsub("Rising Pune Supergiants", "Rising Pune Supergiant", deliveries\)batting_team) deliveries\(bowling_team <- gsub("Rising Pune Supergiants", "Rising Pune Supergiant", deliveries\)bowling_team) # Question 1 How many matches ended in “tie” and played “super-over”? 

tie_finished_matches <- matches %>% filter(result == “tie”) played_supper_over_all <- deliveries %>% filter(is_super_over == 1) played_supper_over_all_S <- select(played_supper_over_all, -19, -20:-21) PSO_duplicates <- duplicated(played_supper_over_all_S\(match_id) PSO_duplicates <- duplicated(played_supper_over_all_S\)match_id, TRUE) Matches_plyd_sup_ovr <- played_supper_over_all_S[!PSO_duplicates, ] Matches_Result_tie_super_plyd <- left_join(tie_finished_matches, Matches_plyd_sup_ovr, join_by(id == match_id)) Matches_Result_tie_super_plyd <- left_join(tie_finished_matches, Matches_plyd_sup_ovr, by = c(“id” = “match_id”)) View(Matches_Result_tie_super_plyd) Num_matches_played_super_finished_tie <- nrow(Matches_Result_tie_super_plyd) print(Num_matches_played_super_finished_tie) #Question 3 How many toss-winning teams have chosen to field and won the matches? What is the percentage of it? Use a suitable graph to show the result visually.

fielding_wins <- matches %>% filter(toss_decision == ‘field’, toss_winner == winner) %>% summarise(count = n()) total_matches <- nrow(matches) fielding_wins_percentage <- (fielding_wins\(count / total_matches) * 100 pie_data <- data.frame(Category = c("Fielding and Winning", "Other"), Count = c(fielding_wins\)count, total_matches - fielding_wins\(count)) ggplot(pie_data, aes(x = "", y = Count, fill = Category)) + geom_bar(stat = "identity", width = 1) + coord_polar("y", start = 0) + geom_label(aes(label = paste0(round(Count/total_matches*100, 2), "%")), position = position_stack(vjust = 0.5)) + labs(fill = "Outcome", x = NULL, y = NULL, title = "Toss Decision Outcome") + theme_void() + theme(legend.position = "right") ggsave("toss_decision_pie_chart.png") print(paste("Number of toss-winning teams that chose to field and won:", fielding_wins\)count)) print(paste(“Percentage of toss-winning teams that chose to field and won:”, round(fielding_wins_percentage, 2), “%”)) #Question 2 Which team had won by maximum runs? For this match, list the venue, date, player of the match, city, and season?  max_runs_match <- matches %>% filter(win_by_runs == max(win_by_runs, na.rm = TRUE)) Detailed_Max_run_win <- max_runs_match %>% select(venue, date, player_of_match, city, season) Detailed_Max_run_win #Question 3 How many toss-winning teams have chosen to field and won the matches? What is the percentage of it? Use a suitable graph to show the result visually.
fielding_wins <- matches %>% filter(toss_decision == ‘field’, toss_winner == winner) %>% summarise(count = n()) total_matches <- nrow(matches) fielding_wins_percentage <- (fielding_wins\(count / total_matches) * 100 pie_data <- data.frame(Category = c("Fielding and Winning", "Other"), Count = c(fielding_wins\)count, total_matches - fielding_wins\(count)) ggplot(pie_data, aes(x = "", y = Count, fill = Category)) + geom_bar(stat = "identity", width = 1) + coord_polar("y", start = 0) + geom_label(aes(label = paste0(round(Count/total_matches*100, 2), "%")), position = position_stack(vjust = 0.5)) + labs(fill = "Outcome", x = NULL, y = NULL, title = "Toss Decision Outcome") + theme_void() + theme(legend.position = "right") ggsave("toss_decision_pie_chart.png") print(paste("Number of toss-winning teams that chose to field and won:", fielding_wins\)count)) print(paste(“Percentage of toss-winning teams that chose to field and won:”, round(fielding_wins_percentage, 2), “%”)) #Question 4 Which toss-winning  team had played maximum dot balls? What is the match number? Against which team this match was played? 

dot_balls <- deliveries %>% filter(total_runs == 0) %>% group_by(match_id, batting_team) %>% summarise(dot_balls = n()) match_details <- merge(dot_balls, matches, by.x = “match_id”, by.y = “id”) toss_winner_dots <- match_details %>% filter(toss_winner == batting_team) max_dot_balls <- toss_winner_dots[which.max(toss_winner_dots$dot_balls),] opposing_team <- ifelse(max_dot_balls\(team1 == max_dot_balls\)batting_team, max_dot_balls\(team2, max_dot_balls\)team1) cat(“The toss-winning team that played the maximum dot balls is:”, max_dot_balls\(batting_team, "\n") cat("The match number is:", max_dot_balls\)match_id, “”) cat(“The match was played against:”, opposing_team, “”)

#Question 5 Which team had won by maximum wicket, by applying the condition “player of the match is a batsman”? 

known_batsmen <- unique(deliveries\(batsman) batsman_wins <- matches %>% filter(player_of_match %in% known_batsmen, win_by_wickets > 0) max_wicket_win <- batsman_wins[which.max(batsman_wins\)win_by_wickets),] cat(“The team that won by the maximum number of wickets with a batsman as the player of the match is:”, max_wicket_win\(winner, "\n") cat("They won by", max_wicket_win\)win_by_wickets, “wickets.”)

#Question 6 Which player has received maximum player of the match awards? Also, show the graphical view taking the franchise into consideration. (Hint: Franchise here means that the player representing the X team in taking all seasons into consideration) 

player_awards <- matches %>% group_by(player_of_match) %>% summarise(awards_count = n()) %>% ungroup() %>% arrange(desc(awards_count)) max_awards_player <- player_awards[1, ] plot_data <- matches %>% filter(player_of_match == max_awards_player\(player_of_match) %>% group_by(team1) %>% summarise(awards_count = n()) %>% bind_rows(matches %>% filter(player_of_match == max_awards_player\)player_of_match) %>% group_by(team2) %>% summarise(awards_count = n())) %>% group_by(team1) %>% summarise(awards_count = sum(awards_count)) %>% ungroup() %>% rename(Franchise = team1) ggplot(plot_data, aes(x = reorder(Franchise, -awards_count), y = awards_count, fill = Franchise)) + geom_bar(stat = “identity”) + theme_minimal() + labs(title = paste(“Player of the Match Awards for”, max_awards_player\(player_of_the_match), x = "Franchise", y = "Number of Awards") + coord_flip() + theme(legend.position = "none") plot_data <- na.omit(plot_data) plot_data\)Franchise <- factor(plot_data\(Franchise, levels = plot_data\)Franchise[order(plot_data$awards_count, decreasing = TRUE)]) ggplot(plot_data, aes(x = Franchise, y = awards_count, fill = Franchise)) + geom_bar(stat = “identity”) + theme_minimal() + labs(title = paste(“Player of the Match Awards for”, max_awards_player\(player_of_the_match), x = "Franchise", y = "Number of Awards") + coord_flip() + theme(legend.position = "none") ggplot(plot_data, aes(x = Franchise, y = awards_count, fill = Franchise)) + geom_bar(stat = "identity") + theme_minimal() + labs(title = paste("Player of the Match Awards for", max_awards_player\)player_of_the_match), x = “Franchise”, y = “Number of Awards”) + coord_flip() + theme(legend.position = “none”)
ggsave(“plot_data.png”)

Question 7 Which team has used a maximum number of bowlers in an innings? List their bowling statistics. (Hint: Bowling statistics include bowler name, runs conceded, wickets taken, and bowling economy) 

bowlers_per_innings <- deliveries %>% group_by(match_id, inning) %>% summarise(bowlers_used = n_distinct(bowler)) max_bowlers_innings <- bowlers_per_innings[which.max(bowlers_per_innings$bowlers_used),]
match_id_max_bowlers <- max_bowlers_innings\(match_id inning_max_bowlers <- max_bowlers_innings\)inning
bowling_stats <- deliveries %>% filter(match_id == match_id_max_bowlers, inning == inning_max_bowlers) %>% group_by(bowler) %>% summarise(runs_conceded = sum(total_runs), wickets_taken = sum(dismissal_kind != "“, na.rm = TRUE), balls_bowled = n()) %>% mutate(bowling_economy = runs_conceded / (balls_bowled / 6))
team_max_bowlers <- deliveries %>% filter(match_id == match_id_max_bowlers, inning == inning_max_bowlers) %>% select(bowling_team) %>% unique()
cat(”The team that used the maximum number of bowlers in an innings is:“, team_max_bowlers$bowling_team,”“)
cat(”Match ID:“, match_id_max_bowlers,”“)
cat(”Inning:“, inning_max_bowlers,”“)
cat(”Bowling Statistics:")
print(bowling_stats)

Question 8 Which teams had won the “super-over” battle while batting first? For these matches, find the season and Player of the Match.

super_over_matches <- deliveries %>% filter(is_super_over == 1) %>% distinct(match_id) super_over_matches <- super_over_matches %>% left_join(deliveries, by = “match_id”)
super_over_winners <- super_over_matches %>% left_join(matches, by = c(“match_id” = “id”))
final_result_A <- super_over_winners %>% select(match_id, team1, season, player_of_match)
print(final_results)
final_results <- final_result_A %>% distinct(match_id, .keep_all = TRUE)
print(final_results)

Question 9 Considering all seasons, find the highest score in IPL. Show the score distribution using a suitable graph. 

total_scores <- deliveries %>% group_by(match_id) %>% summarise(total_runs = sum(total_runs)) highest_score <- max(total_scores$total_runs)
cat(“The highest score in IPL is:”, highest_score, “”)
ggplot(total_scores, aes(x = total_runs)) + geom_histogram(binwidth = 10, fill = “blue”, color = “red”) + labs(title = “Distribution of Total Scores in IPL”, x = “Total Score”, y = “Frequency”) + theme_minimal() + coord_flip() + theme(legend.position = “none”) ggsave(“score_distribution.png”)

Question 10 Which IPL Team is most successful? The most successful team is the one who has one the greatest number of matches, considering all seasons. Also, interpret the result with the help of plots/graphs.

team_wins <- matches %>% group_by(winner) %>% summarise(wins = n()) %>% arrange(desc(wins)) most_successful_team <- team_wins[1, ]
cat(“The most successful IPL team is:”, most_successful_team\(winner, "with", most_successful_team\)wins, “wins.”)
ggplot(team_wins, aes(x = reorder(winner, wins), y = wins, fill = winner)) + geom_bar(stat = “identity”) + theme_minimal() + labs(title = “Number of Wins for Each IPL Team”, x = “Team”, y = “Wins”) + coord_flip() + theme(legend.position = “none”) ggsave(“ipl_team_success.png”)