Burcu Demirgülle

library(tidyverse)
library(ggplot2)
library(kableExtra)
url<-url("https://github.com/pjournal/mef03-bdemirgulle/blob/master/atp_tennis_data_2017.RData?raw=TRUE")
atp_tennis<-load(url)

Rank countries (flag codes) by the number of singles champions

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

Rank countries which did not get any singles championships by the games won when they win the match

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

Roger Federer Lost Tourney Round Details

roger_federer <- player_df %>% filter (first_name=="Roger",last_name=="Federer")
roger_federer_match_lost <- semi_join(score_df,roger_federer,by= c("loser_player_id"="player_id"))%>% count(tourney_round_name,sort=T)
roger_federer_match_lost
## # A tibble: 4 x 2
##   tourney_round_name     n
##   <chr>              <int>
## 1 Round of 16            2
## 2 Finals                 1
## 3 Quarter-Finals         1
## 4 Semi-Finals            1

Roger Federer Winner Tourney Round Details

roger_federer <- player_df %>% filter (first_name=="Roger",last_name=="Federer")
roger_federer_match_win <- semi_join(score_df,roger_federer,by= c("winner_player_id"="player_id"))%>% count(tourney_round_name,sort=T)
roger_federer_match_win
## # A tibble: 8 x 2
##   tourney_round_name     n
##   <chr>              <int>
## 1 Round of 32           10
## 2 Round of 16            9
## 3 Quarter-Finals         8
## 4 Semi-Finals            8
## 5 Finals                 7
## 6 Round of 64            5
## 7 Round of 128           3
## 8 Round Robin            3

The winners against to Roger Federer

roger_federer <- player_df %>% filter (first_name=="Roger",last_name=="Federer")
roger_federer_match_lost <- semi_join(score_df,roger_federer,by= c("loser_player_id"="player_id"))
roger_federer_match_lost_winner_player <- semi_join(player_df,roger_federer_match_lost,by= c("player_id"="winner_player_id"))
roger_federer_match_lost_winner_player
## # A tibble: 5 x 13
##   player_id player_slug first_name last_name flag_code residence
##   <chr>     <chr>       <chr>      <chr>     <chr>     <chr>    
## 1 d683      juan-marti~ Juan Mart~ del Potro ARG       Tandil, ~
## 2 d864      evgeny-don~ Evgeny     Donskoy   RUS       Moscow, ~
## 3 gb88      david-goff~ David      Goffin    BEL       Monte Ca~
## 4 h355      tommy-haas  Tommy      Haas      GER       Bradento~
## 5 z355      alexander-~ Alexander  Zverev    GER       Monte Ca~
## # ... with 7 more variables: birth_place <chr>, birth_date <date>,
## #   turned_pro <dbl>, weight_kg <dbl>, height_cm <dbl>, handedness <chr>,
## #   backhand <chr>

Avarage KG and Height of the winners against to Roger Federer

roger_federer_match_lost_winner_player_kg<-roger_federer_match_lost_winner_player %>% summarise(mean_weight=mean(weight_kg),mean_height=mean(height_cm))  
roger_federer_match_lost_winner_player_kg
## # A tibble: 1 x 2
##   mean_weight mean_height
##         <dbl>       <dbl>
## 1        81.8        190.