This repository has been archived by the owner on Jan 2, 2020. It is now read-only.
/
ATP_Assignment.Rmd
142 lines (87 loc) · 3.31 KB
/
ATP_Assignment.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
---
title: "ATP_Assignment"
author: "Bulent Buyuk"
date: "27 11 2019"
output: html_document
---
## 1- Rank countries(flag codes) by the singles champions.
```{r}
library(tidyverse)
our_data <- "~/atp_tennis_data_2017.RData"
load(our_data)
task1 <- inner_join(tourney_df, player_df, by = c("singles_winner_player_id"="player_id"))
champ_flags_df<- task1 %>%
group_by(flag_code) %>% count(flag_code, sort=TRUE)
champ_flags_df
```
## 2- Rank countries which did not get any singles championship by the games won when they win the match.
```{r}
nonchamp_players<- player_df %>%
select(player_id, flag_code) %>%
anti_join(., champ_flags_df)
```
```{r}
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))
```
## 3- Rank names of players who are champions in both singles and doubles in the same tournament.
```{r}
both_champions<- tourney_df %>%
filter(singles_winner_player_id==doubles_winner_1_player_id|
singles_winner_player_id==doubles_winner_2_player_id)
names_player_bc<- inner_join(both_champions, player_df, by = c("singles_winner_player_id"="player_id"))
names_player_bc$player_slug
```
## 4- Which hand do players use who champions in singles.
```{r}
task4 <- inner_join(tourney_df, player_df, by = c("singles_winner_player_id"="player_id"))
which_hand<- task1 %>%
group_by(handedness) %>% count(handedness)
which_hand
```
=======
---
title: "ATP_Assignment"
author: "Bulent Buyuk"
date: "27 11 2019"
output: html_document
---
## 1- Rank countries(flag codes) by the singles champions.
```{r}
library(tidyverse)
our_data <- "~/atp_tennis_data_2017.RData"
load(our_data)
task1 <- inner_join(tourney_df, player_df, by = c("singles_winner_player_id"="player_id"))
champ_flags_df<- task1 %>%
group_by(flag_code) %>% count(flag_code, sort=TRUE)
champ_flags_df
```
## 2- Rank countries which did not get any singles championship by the games won when they win the match.
```{r}
nonchamp_players<- player_df %>%
select(player_id, flag_code) %>%
anti_join(., champ_flags_df)
```
```{r}
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))
```
## 3- Rank names of players who are champions in both singles and doubles in the same tournament.
```{r}
both_champions<- tourney_df %>%
filter(singles_winner_player_id==doubles_winner_1_player_id|
singles_winner_player_id==doubles_winner_2_player_id)
names_player_bc<- inner_join(both_champions, player_df, by = c("singles_winner_player_id"="player_id"))
names_player_bc$player_slug
```
## 4- Which hand do players use who champions in singles.
```{r}
task4 <- inner_join(tourney_df, player_df, by = c("singles_winner_player_id"="player_id"))
which_hand<- task1 %>%
group_by(handedness) %>% count(handedness)
which_hand
```