url<-url("https://github.com/pjournal/mef03-demirefe91/blob/master/atp_tennis_data_2017.RData?raw=TRUE")
atp_data<-load(url)
glimpse(atp_data)
## chr [1:6] "tourney_df" "player_df" "stats_df" "score_df" "rank_df" ...
singles_winners<-left_join(tourney_df,player_df,by=c("singles_winner_player_id"="player_id"))
champ_flags_df<-singles_winners%>%select(singles_winner_player_id,flag_code)%>%count(flag_code,sort=T)
champ_flags_df
## # A tibble: 21 x 2
## flag_code n
## <chr> <int>
## 1 ESP 11
## 2 USA 9
## 3 SUI 8
## 4 FRA 7
## 5 GER 7
## 6 BUL 4
## 7 ARG 2
## 8 BEL 2
## 9 BIH 2
## 10 CRO 2
## # … with 11 more rows
nonchamp_players<- player_df %>%select(player_id, flag_code) %>%anti_join(., champ_flags_df,by="flag_code")
nonchamp_players %>% left_join(.,score_df, by= c("player_id"="winner_player_id")) %>%group_by(flag_code) %>%summarise(total_won= sum(winner_games_won, na.rm=TRUE)) %>%arrange(desc(total_won))
## # A tibble: 93 x 2
## flag_code total_won
## <chr> <dbl>
## 1 AUS 1989
## 2 CZE 1209
## 3 CAN 1190
## 4 SVK 889
## 5 BRA 873
## 6 POR 621
## 7 RSA 566
## 8 KAZ 495
## 9 KOR 438
## 10 GEO 377
## # … with 83 more rows
prize_money <- inner_join(tourney_df, player_df, by=c("singles_winner_player_id" = "player_id")) %>%
count(handedness, backhand) %>% arrange(desc(n))
prize_money
## # A tibble: 4 x 3
## handedness backhand n
## <chr> <chr> <int>
## 1 Right-Handed Two-Handed Backhand 41
## 2 Right-Handed One-Handed Backhand 17
## 3 Left-Handed Two-Handed Backhand 8
## 4 Left-Handed One-Handed Backhand 1
stats_df <- stats_df %>% mutate(num_tourney_id=as.numeric(tourney_id))
tournaments <- inner_join(tourney_df, stats_df, by=c("tourney_id" ="num_tourney_id")) %>%
group_by(tourney_name) %>% summarise(total_duration = sum(match_duration)) %>% arrange(desc(total_duration))
tournaments
## # A tibble: 67 x 2
## tourney_name total_duration
## <chr> <dbl>
## 1 Australian Open 29548
## 2 Roland Garros 29516
## 3 Wimbledon 28437
## 4 US Open 18702
## 5 Miami Open presented by Itaú 12732
## 6 BNP Paribas Open 12551
## 7 Coupe Rogers 7747
## 8 Rolex Monte-Carlo Masters 7542
## 9 Mutua Madrid Open 7531
## 10 Internazionali BNL d’Italia 7523
## # … with 57 more rows