library(RCurl)
#Getting data from github repository
tour_info <-read.csv(text=getURL("https://raw.githubusercontent.com/thasleem1/DATA607/master/tournamentinfo.txt"))
#Formation of data frame with column
colnames(tour_info)<-c("tour_info")
#Removing the -- and + data
tour_data<-data.frame(gsub("-+","",tour_info$tour_info))
tournament <- tour_data[tour_data != ""] # Remove the emtpy lines
tournament <- tour_data[c(3:nrow(tour_data)),] # Remove the header information
library(stringr)
#Extract Line1 and Line2
Line1 <- tournament[str_detect(substr(tournament, 1, 6), "[0-9]")]
Line2 <- tournament[str_detect(substr(tournament, 1, 6), "[A-Z]{2,2}")]
library("knitr")
library("kableExtra")
kable(data.frame(head(Line1, n=5))) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>%
row_spec(0, bold = T, color = "white", background = "#ea7872")| head.Line1..n…5. |
|---|
| 1 | GARY HUA |6.0 |W 39|W 21|W 18|W 14|W 7|D 12|D 4| |
| 2 | DAKSHESH DARURI |6.0 |W 63|W 58|L 4|W 17|W 16|W 20|W 7| |
| 3 | ADITYA BAJAJ |6.0 |L 8|W 61|W 25|W 21|W 11|W 13|W 12| |
| 4 | PATRICK H SCHILLING |5.5 |W 23|D 28|W 2|W 26|D 5|W 19|D 1| |
| 5 | HANSHI ZUO |5.5 |W 45|W 37|D 12|D 13|D 4|W 14|W 17| |
kable(data.frame(head(Line2, n=5))) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>%
row_spec(0, bold = T, color = "white", background = "#ea7872")| head.Line2..n…5. |
|---|
| ON | 15445895 / R: 1794 >1817 |N:2 |W |B |W |B |W |B |W | |
| MI | 14598900 / R: 1553 >1663 |N:2 |B |W |B |W |B |W |B | |
| MI | 14959604 / R: 1384 >1640 |N:2 |W |B |W |B |W |B |W | |
| MI | 12616049 / R: 1716 >1744 |N:2 |W |B |W |B |W |B |B | |
| MI | 14601533 / R: 1655 >1690 |N:2 |B |W |B |W |B |W |B | |
#Merging Line1 and Line2 as a single record
merge <- data.frame(Line1, Line2)
#Concatenate the Line1 and Line2
library(sqldf)
player_data <- sqldf("Select Line1||Line2 as Line1_Line2_Merged from merge")
kable(data.frame(head(player_data, n=5))) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>%
row_spec(0, bold = T, color = "white", background = "#ea7872")| Line1_Line2_Merged |
|---|
| 1 | GARY HUA |6.0 |W 39|W 21|W 18|W 14|W 7|D 12|D 4| ON | 15445895 / R: 1794 >1817 |N:2 |W |B |W |B |W |B |W | |
| 2 | DAKSHESH DARURI |6.0 |W 63|W 58|L 4|W 17|W 16|W 20|W 7| MI | 14598900 / R: 1553 >1663 |N:2 |B |W |B |W |B |W |B | |
| 3 | ADITYA BAJAJ |6.0 |L 8|W 61|W 25|W 21|W 11|W 13|W 12| MI | 14959604 / R: 1384 >1640 |N:2 |W |B |W |B |W |B |W | |
| 4 | PATRICK H SCHILLING |5.5 |W 23|D 28|W 2|W 26|D 5|W 19|D 1| MI | 12616049 / R: 1716 >1744 |N:2 |W |B |W |B |W |B |B | |
| 5 | HANSHI ZUO |5.5 |W 45|W 37|D 12|D 13|D 4|W 14|W 17| MI | 14601533 / R: 1655 >1690 |N:2 |B |W |B |W |B |W |B | |
library(tidyr)
#Cleansing and formatting the data
cleansed_data <- player_data %>%
# Split the single column of text into multiple columns
separate(Line1_Line2_Merged, into = c("Pair", "Player_Name","Total","Round1","Round2","Round3","Round4","Round5","Round6","Round7","State","USCFID_Pre_Post_Rtg","Pts","R1","R2","R3","R4","R5","R6","R7"), sep = '\\|')
cleansed_data$USCFID = as.numeric(substr(cleansed_data$USCFID_Pre_Post_Rtg, 1, 9))
cleansed_data$PreRtg = as.numeric(substr(cleansed_data$USCFID_Pre_Post_Rtg, 16, 19))
cleansed_data$PostRtg = as.numeric(substr(cleansed_data$USCFID_Pre_Post_Rtg, 24, 27))
cleansed_data$Pair = as.numeric(cleansed_data$Pair)
#library(stringi)
#Converting the Character to Number datatype
for (i in 4:10){
cleansed_data[,i] <- as.numeric(gsub("[^0-9]+", "", cleansed_data[,i]))
}
kable(data.frame(head(cleansed_data))) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>%
row_spec(0, bold = T, color = "white", background = "#ea7872") %>%
scroll_box(width = "100%", height = "200px")| Pair | Player_Name | Total | Round1 | Round2 | Round3 | Round4 | Round5 | Round6 | Round7 | State | USCFID_Pre_Post_Rtg | Pts | R1 | R2 | R3 | R4 | R5 | R6 | R7 | USCFID | PreRtg | PostRtg |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | GARY HUA | 6.0 | 39 | 21 | 18 | 14 | 7 | 12 | 4 | ON | 15445895 / R: 1794 >1817 | N:2 | W | B | W | B | W | B | W | 15445895 | 1794 | 1817 |
| 2 | DAKSHESH DARURI | 6.0 | 63 | 58 | 4 | 17 | 16 | 20 | 7 | MI | 14598900 / R: 1553 >1663 | N:2 | B | W | B | W | B | W | B | 14598900 | 1553 | 1663 |
| 3 | ADITYA BAJAJ | 6.0 | 8 | 61 | 25 | 21 | 11 | 13 | 12 | MI | 14959604 / R: 1384 >1640 | N:2 | W | B | W | B | W | B | W | 14959604 | 1384 | 1640 |
| 4 | PATRICK H SCHILLING | 5.5 | 23 | 28 | 2 | 26 | 5 | 19 | 1 | MI | 12616049 / R: 1716 >1744 | N:2 | W | B | W | B | W | B | B | 12616049 | 1716 | 1744 |
| 5 | HANSHI ZUO | 5.5 | 45 | 37 | 12 | 13 | 4 | 14 | 17 | MI | 14601533 / R: 1655 >1690 | N:2 | B | W | B | W | B | W | B | 14601533 | 1655 | 1690 |
| 6 | HANSEN SONG | 5.0 | 34 | 29 | 11 | 35 | 10 | 27 | 21 | OH | 15055204 / R: 1686 >1687 | N:3 | W | B | W | B | B | W | B | 15055204 | 1686 | 1687 |
cleansed_data_subset <- subset(cleansed_data, select=c(Pair,PreRtg,Round1,Round2,Round3,Round4,Round5,Round6,Round7))
library(reshape2)
#Aggregate the data
melt_data <- melt(cleansed_data_subset, id.vars=c("Pair", "PreRtg"))
agg_data <- melt_data[order(melt_data$Pair,melt_data$variable),]
kable(data.frame(agg_data)) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>%
row_spec(0, bold = T, color = "white", background = "#ea7872") %>%
scroll_box(width = "100%", height = "200px")| Pair | PreRtg | variable | value | |
|---|---|---|---|---|
| 1 | 1 | 1794 | Round1 | 39 |
| 65 | 1 | 1794 | Round2 | 21 |
| 129 | 1 | 1794 | Round3 | 18 |
| 193 | 1 | 1794 | Round4 | 14 |
| 257 | 1 | 1794 | Round5 | 7 |
| 321 | 1 | 1794 | Round6 | 12 |
| 385 | 1 | 1794 | Round7 | 4 |
| 2 | 2 | 1553 | Round1 | 63 |
| 66 | 2 | 1553 | Round2 | 58 |
| 130 | 2 | 1553 | Round3 | 4 |
| 194 | 2 | 1553 | Round4 | 17 |
| 258 | 2 | 1553 | Round5 | 16 |
| 322 | 2 | 1553 | Round6 | 20 |
| 386 | 2 | 1553 | Round7 | 7 |
| 3 | 3 | 1384 | Round1 | 8 |
| 67 | 3 | 1384 | Round2 | 61 |
| 131 | 3 | 1384 | Round3 | 25 |
| 195 | 3 | 1384 | Round4 | 21 |
| 259 | 3 | 1384 | Round5 | 11 |
| 323 | 3 | 1384 | Round6 | 13 |
| 387 | 3 | 1384 | Round7 | 12 |
| 4 | 4 | 1716 | Round1 | 23 |
| 68 | 4 | 1716 | Round2 | 28 |
| 132 | 4 | 1716 | Round3 | 2 |
| 196 | 4 | 1716 | Round4 | 26 |
| 260 | 4 | 1716 | Round5 | 5 |
| 324 | 4 | 1716 | Round6 | 19 |
| 388 | 4 | 1716 | Round7 | 1 |
| 5 | 5 | 1655 | Round1 | 45 |
| 69 | 5 | 1655 | Round2 | 37 |
| 133 | 5 | 1655 | Round3 | 12 |
| 197 | 5 | 1655 | Round4 | 13 |
| 261 | 5 | 1655 | Round5 | 4 |
| 325 | 5 | 1655 | Round6 | 14 |
| 389 | 5 | 1655 | Round7 | 17 |
| 6 | 6 | 1686 | Round1 | 34 |
| 70 | 6 | 1686 | Round2 | 29 |
| 134 | 6 | 1686 | Round3 | 11 |
| 198 | 6 | 1686 | Round4 | 35 |
| 262 | 6 | 1686 | Round5 | 10 |
| 326 | 6 | 1686 | Round6 | 27 |
| 390 | 6 | 1686 | Round7 | 21 |
| 7 | 7 | 1649 | Round1 | 57 |
| 71 | 7 | 1649 | Round2 | 46 |
| 135 | 7 | 1649 | Round3 | 13 |
| 199 | 7 | 1649 | Round4 | 11 |
| 263 | 7 | 1649 | Round5 | 1 |
| 327 | 7 | 1649 | Round6 | 9 |
| 391 | 7 | 1649 | Round7 | 2 |
| 8 | 8 | 1641 | Round1 | 3 |
| 72 | 8 | 1641 | Round2 | 32 |
| 136 | 8 | 1641 | Round3 | 14 |
| 200 | 8 | 1641 | Round4 | 9 |
| 264 | 8 | 1641 | Round5 | 47 |
| 328 | 8 | 1641 | Round6 | 28 |
| 392 | 8 | 1641 | Round7 | 19 |
| 9 | 9 | 1411 | Round1 | 25 |
| 73 | 9 | 1411 | Round2 | 18 |
| 137 | 9 | 1411 | Round3 | 59 |
| 201 | 9 | 1411 | Round4 | 8 |
| 265 | 9 | 1411 | Round5 | 26 |
| 329 | 9 | 1411 | Round6 | 7 |
| 393 | 9 | 1411 | Round7 | 20 |
| 10 | 10 | 1365 | Round1 | 16 |
| 74 | 10 | 1365 | Round2 | 19 |
| 138 | 10 | 1365 | Round3 | 55 |
| 202 | 10 | 1365 | Round4 | 31 |
| 266 | 10 | 1365 | Round5 | 6 |
| 330 | 10 | 1365 | Round6 | 25 |
| 394 | 10 | 1365 | Round7 | 18 |
| 11 | 11 | 1712 | Round1 | 38 |
| 75 | 11 | 1712 | Round2 | 56 |
| 139 | 11 | 1712 | Round3 | 6 |
| 203 | 11 | 1712 | Round4 | 7 |
| 267 | 11 | 1712 | Round5 | 3 |
| 331 | 11 | 1712 | Round6 | 34 |
| 395 | 11 | 1712 | Round7 | 26 |
| 12 | 12 | 1663 | Round1 | 42 |
| 76 | 12 | 1663 | Round2 | 33 |
| 140 | 12 | 1663 | Round3 | 5 |
| 204 | 12 | 1663 | Round4 | 38 |
| 268 | 12 | 1663 | Round5 | NA |
| 332 | 12 | 1663 | Round6 | 1 |
| 396 | 12 | 1663 | Round7 | 3 |
| 13 | 13 | 1666 | Round1 | 36 |
| 77 | 13 | 1666 | Round2 | 27 |
| 141 | 13 | 1666 | Round3 | 7 |
| 205 | 13 | 1666 | Round4 | 5 |
| 269 | 13 | 1666 | Round5 | 33 |
| 333 | 13 | 1666 | Round6 | 3 |
| 397 | 13 | 1666 | Round7 | 32 |
| 14 | 14 | 1610 | Round1 | 54 |
| 78 | 14 | 1610 | Round2 | 44 |
| 142 | 14 | 1610 | Round3 | 8 |
| 206 | 14 | 1610 | Round4 | 1 |
| 270 | 14 | 1610 | Round5 | 27 |
| 334 | 14 | 1610 | Round6 | 5 |
| 398 | 14 | 1610 | Round7 | 31 |
| 15 | 15 | 1220 | Round1 | 19 |
| 79 | 15 | 1220 | Round2 | 16 |
| 143 | 15 | 1220 | Round3 | 30 |
| 207 | 15 | 1220 | Round4 | 22 |
| 271 | 15 | 1220 | Round5 | 54 |
| 335 | 15 | 1220 | Round6 | 33 |
| 399 | 15 | 1220 | Round7 | 38 |
| 16 | 16 | 1604 | Round1 | 10 |
| 80 | 16 | 1604 | Round2 | 15 |
| 144 | 16 | 1604 | Round3 | NA |
| 208 | 16 | 1604 | Round4 | 39 |
| 272 | 16 | 1604 | Round5 | 2 |
| 336 | 16 | 1604 | Round6 | 36 |
| 400 | 16 | 1604 | Round7 | NA |
| 17 | 17 | 1629 | Round1 | 48 |
| 81 | 17 | 1629 | Round2 | 41 |
| 145 | 17 | 1629 | Round3 | 26 |
| 209 | 17 | 1629 | Round4 | 2 |
| 273 | 17 | 1629 | Round5 | 23 |
| 337 | 17 | 1629 | Round6 | 22 |
| 401 | 17 | 1629 | Round7 | 5 |
| 18 | 18 | 1600 | Round1 | 47 |
| 82 | 18 | 1600 | Round2 | 9 |
| 146 | 18 | 1600 | Round3 | 1 |
| 210 | 18 | 1600 | Round4 | 32 |
| 274 | 18 | 1600 | Round5 | 19 |
| 338 | 18 | 1600 | Round6 | 38 |
| 402 | 18 | 1600 | Round7 | 10 |
| 19 | 19 | 1564 | Round1 | 15 |
| 83 | 19 | 1564 | Round2 | 10 |
| 147 | 19 | 1564 | Round3 | 52 |
| 211 | 19 | 1564 | Round4 | 28 |
| 275 | 19 | 1564 | Round5 | 18 |
| 339 | 19 | 1564 | Round6 | 4 |
| 403 | 19 | 1564 | Round7 | 8 |
| 20 | 20 | 1595 | Round1 | 40 |
| 84 | 20 | 1595 | Round2 | 49 |
| 148 | 20 | 1595 | Round3 | 23 |
| 212 | 20 | 1595 | Round4 | 41 |
| 276 | 20 | 1595 | Round5 | 28 |
| 340 | 20 | 1595 | Round6 | 2 |
| 404 | 20 | 1595 | Round7 | 9 |
| 21 | 21 | 1563 | Round1 | 43 |
| 85 | 21 | 1563 | Round2 | 1 |
| 149 | 21 | 1563 | Round3 | 47 |
| 213 | 21 | 1563 | Round4 | 3 |
| 277 | 21 | 1563 | Round5 | 40 |
| 341 | 21 | 1563 | Round6 | 39 |
| 405 | 21 | 1563 | Round7 | 6 |
| 22 | 22 | 1555 | Round1 | 64 |
| 86 | 22 | 1555 | Round2 | 52 |
| 150 | 22 | 1555 | Round3 | 28 |
| 214 | 22 | 1555 | Round4 | 15 |
| 278 | 22 | 1555 | Round5 | NA |
| 342 | 22 | 1555 | Round6 | 17 |
| 406 | 22 | 1555 | Round7 | 40 |
| 23 | 23 | 1363 | Round1 | 4 |
| 87 | 23 | 1363 | Round2 | 43 |
| 151 | 23 | 1363 | Round3 | 20 |
| 215 | 23 | 1363 | Round4 | 58 |
| 279 | 23 | 1363 | Round5 | 17 |
| 343 | 23 | 1363 | Round6 | 37 |
| 407 | 23 | 1363 | Round7 | 46 |
| 24 | 24 | 1229 | Round1 | 28 |
| 88 | 24 | 1229 | Round2 | 47 |
| 152 | 24 | 1229 | Round3 | 43 |
| 216 | 24 | 1229 | Round4 | 25 |
| 280 | 24 | 1229 | Round5 | 60 |
| 344 | 24 | 1229 | Round6 | 44 |
| 408 | 24 | 1229 | Round7 | 39 |
| 25 | 25 | 1745 | Round1 | 9 |
| 89 | 25 | 1745 | Round2 | 53 |
| 153 | 25 | 1745 | Round3 | 3 |
| 217 | 25 | 1745 | Round4 | 24 |
| 281 | 25 | 1745 | Round5 | 34 |
| 345 | 25 | 1745 | Round6 | 10 |
| 409 | 25 | 1745 | Round7 | 47 |
| 26 | 26 | 1579 | Round1 | 49 |
| 90 | 26 | 1579 | Round2 | 40 |
| 154 | 26 | 1579 | Round3 | 17 |
| 218 | 26 | 1579 | Round4 | 4 |
| 282 | 26 | 1579 | Round5 | 9 |
| 346 | 26 | 1579 | Round6 | 32 |
| 410 | 26 | 1579 | Round7 | 11 |
| 27 | 27 | 1552 | Round1 | 51 |
| 91 | 27 | 1552 | Round2 | 13 |
| 155 | 27 | 1552 | Round3 | 46 |
| 219 | 27 | 1552 | Round4 | 37 |
| 283 | 27 | 1552 | Round5 | 14 |
| 347 | 27 | 1552 | Round6 | 6 |
| 411 | 27 | 1552 | Round7 | NA |
| 28 | 28 | 1507 | Round1 | 24 |
| 92 | 28 | 1507 | Round2 | 4 |
| 156 | 28 | 1507 | Round3 | 22 |
| 220 | 28 | 1507 | Round4 | 19 |
| 284 | 28 | 1507 | Round5 | 20 |
| 348 | 28 | 1507 | Round6 | 8 |
| 412 | 28 | 1507 | Round7 | 36 |
| 29 | 29 | 1602 | Round1 | 50 |
| 93 | 29 | 1602 | Round2 | 6 |
| 157 | 29 | 1602 | Round3 | 38 |
| 221 | 29 | 1602 | Round4 | 34 |
| 285 | 29 | 1602 | Round5 | 52 |
| 349 | 29 | 1602 | Round6 | 48 |
| 413 | 29 | 1602 | Round7 | NA |
| 30 | 30 | 1522 | Round1 | 52 |
| 94 | 30 | 1522 | Round2 | 64 |
| 158 | 30 | 1522 | Round3 | 15 |
| 222 | 30 | 1522 | Round4 | 55 |
| 286 | 30 | 1522 | Round5 | 31 |
| 350 | 30 | 1522 | Round6 | 61 |
| 414 | 30 | 1522 | Round7 | 50 |
| 31 | 31 | 1494 | Round1 | 58 |
| 95 | 31 | 1494 | Round2 | 55 |
| 159 | 31 | 1494 | Round3 | 64 |
| 223 | 31 | 1494 | Round4 | 10 |
| 287 | 31 | 1494 | Round5 | 30 |
| 351 | 31 | 1494 | Round6 | 50 |
| 415 | 31 | 1494 | Round7 | 14 |
| 32 | 32 | 1441 | Round1 | 61 |
| 96 | 32 | 1441 | Round2 | 8 |
| 160 | 32 | 1441 | Round3 | 44 |
| 224 | 32 | 1441 | Round4 | 18 |
| 288 | 32 | 1441 | Round5 | 51 |
| 352 | 32 | 1441 | Round6 | 26 |
| 416 | 32 | 1441 | Round7 | 13 |
| 33 | 33 | 1449 | Round1 | 60 |
| 97 | 33 | 1449 | Round2 | 12 |
| 161 | 33 | 1449 | Round3 | 50 |
| 225 | 33 | 1449 | Round4 | 36 |
| 289 | 33 | 1449 | Round5 | 13 |
| 353 | 33 | 1449 | Round6 | 15 |
| 417 | 33 | 1449 | Round7 | 51 |
| 34 | 34 | 1399 | Round1 | 6 |
| 98 | 34 | 1399 | Round2 | 60 |
| 162 | 34 | 1399 | Round3 | 37 |
| 226 | 34 | 1399 | Round4 | 29 |
| 290 | 34 | 1399 | Round5 | 25 |
| 354 | 34 | 1399 | Round6 | 11 |
| 418 | 34 | 1399 | Round7 | 52 |
| 35 | 35 | 1438 | Round1 | 46 |
| 99 | 35 | 1438 | Round2 | 38 |
| 163 | 35 | 1438 | Round3 | 56 |
| 227 | 35 | 1438 | Round4 | 6 |
| 291 | 35 | 1438 | Round5 | 57 |
| 355 | 35 | 1438 | Round6 | 52 |
| 419 | 35 | 1438 | Round7 | 48 |
| 36 | 36 | 1355 | Round1 | 13 |
| 100 | 36 | 1355 | Round2 | 57 |
| 164 | 36 | 1355 | Round3 | 51 |
| 228 | 36 | 1355 | Round4 | 33 |
| 292 | 36 | 1355 | Round5 | NA |
| 356 | 36 | 1355 | Round6 | 16 |
| 420 | 36 | 1355 | Round7 | 28 |
| 37 | 37 | 980 | Round1 | NA |
| 101 | 37 | 980 | Round2 | 5 |
| 165 | 37 | 980 | Round3 | 34 |
| 229 | 37 | 980 | Round4 | 27 |
| 293 | 37 | 980 | Round5 | NA |
| 357 | 37 | 980 | Round6 | 23 |
| 421 | 37 | 980 | Round7 | 61 |
| 38 | 38 | 1423 | Round1 | 11 |
| 102 | 38 | 1423 | Round2 | 35 |
| 166 | 38 | 1423 | Round3 | 29 |
| 230 | 38 | 1423 | Round4 | 12 |
| 294 | 38 | 1423 | Round5 | NA |
| 358 | 38 | 1423 | Round6 | 18 |
| 422 | 38 | 1423 | Round7 | 15 |
| 39 | 39 | 1436 | Round1 | 1 |
| 103 | 39 | 1436 | Round2 | 54 |
| 167 | 39 | 1436 | Round3 | 40 |
| 231 | 39 | 1436 | Round4 | 16 |
| 295 | 39 | 1436 | Round5 | 44 |
| 359 | 39 | 1436 | Round6 | 21 |
| 423 | 39 | 1436 | Round7 | 24 |
| 40 | 40 | 1348 | Round1 | 20 |
| 104 | 40 | 1348 | Round2 | 26 |
| 168 | 40 | 1348 | Round3 | 39 |
| 232 | 40 | 1348 | Round4 | 59 |
| 296 | 40 | 1348 | Round5 | 21 |
| 360 | 40 | 1348 | Round6 | 56 |
| 424 | 40 | 1348 | Round7 | 22 |
| 41 | 41 | 1403 | Round1 | 59 |
| 105 | 41 | 1403 | Round2 | 17 |
| 169 | 41 | 1403 | Round3 | 58 |
| 233 | 41 | 1403 | Round4 | 20 |
| 297 | 41 | 1403 | Round5 | NA |
| 361 | 41 | 1403 | Round6 | NA |
| 425 | 41 | 1403 | Round7 | NA |
| 42 | 42 | 1332 | Round1 | 12 |
| 106 | 42 | 1332 | Round2 | 50 |
| 170 | 42 | 1332 | Round3 | 57 |
| 234 | 42 | 1332 | Round4 | 60 |
| 298 | 42 | 1332 | Round5 | 61 |
| 362 | 42 | 1332 | Round6 | 64 |
| 426 | 42 | 1332 | Round7 | 56 |
| 43 | 43 | 1283 | Round1 | 21 |
| 107 | 43 | 1283 | Round2 | 23 |
| 171 | 43 | 1283 | Round3 | 24 |
| 235 | 43 | 1283 | Round4 | 63 |
| 299 | 43 | 1283 | Round5 | 59 |
| 363 | 43 | 1283 | Round6 | 46 |
| 427 | 43 | 1283 | Round7 | 55 |
| 44 | 44 | 1199 | Round1 | NA |
| 108 | 44 | 1199 | Round2 | 14 |
| 172 | 44 | 1199 | Round3 | 32 |
| 236 | 44 | 1199 | Round4 | 53 |
| 300 | 44 | 1199 | Round5 | 39 |
| 364 | 44 | 1199 | Round6 | 24 |
| 428 | 44 | 1199 | Round7 | 59 |
| 45 | 45 | 1242 | Round1 | 5 |
| 109 | 45 | 1242 | Round2 | 51 |
| 173 | 45 | 1242 | Round3 | 60 |
| 237 | 45 | 1242 | Round4 | 56 |
| 301 | 45 | 1242 | Round5 | 63 |
| 365 | 45 | 1242 | Round6 | 55 |
| 429 | 45 | 1242 | Round7 | 58 |
| 46 | 46 | 377 | Round1 | 35 |
| 110 | 46 | 377 | Round2 | 7 |
| 174 | 46 | 377 | Round3 | 27 |
| 238 | 46 | 377 | Round4 | 50 |
| 302 | 46 | 377 | Round5 | 64 |
| 366 | 46 | 377 | Round6 | 43 |
| 430 | 46 | 377 | Round7 | 23 |
| 47 | 47 | 1362 | Round1 | 18 |
| 111 | 47 | 1362 | Round2 | 24 |
| 175 | 47 | 1362 | Round3 | 21 |
| 239 | 47 | 1362 | Round4 | 61 |
| 303 | 47 | 1362 | Round5 | 8 |
| 367 | 47 | 1362 | Round6 | 51 |
| 431 | 47 | 1362 | Round7 | 25 |
| 48 | 48 | 1382 | Round1 | 17 |
| 112 | 48 | 1382 | Round2 | 63 |
| 176 | 48 | 1382 | Round3 | NA |
| 240 | 48 | 1382 | Round4 | 52 |
| 304 | 48 | 1382 | Round5 | NA |
| 368 | 48 | 1382 | Round6 | 29 |
| 432 | 48 | 1382 | Round7 | 35 |
| 49 | 49 | 1291 | Round1 | 26 |
| 113 | 49 | 1291 | Round2 | 20 |
| 177 | 49 | 1291 | Round3 | 63 |
| 241 | 49 | 1291 | Round4 | 64 |
| 305 | 49 | 1291 | Round5 | 58 |
| 369 | 49 | 1291 | Round6 | NA |
| 433 | 49 | 1291 | Round7 | NA |
| 50 | 50 | 1056 | Round1 | 29 |
| 114 | 50 | 1056 | Round2 | 42 |
| 178 | 50 | 1056 | Round3 | 33 |
| 242 | 50 | 1056 | Round4 | 46 |
| 306 | 50 | 1056 | Round5 | NA |
| 370 | 50 | 1056 | Round6 | 31 |
| 434 | 50 | 1056 | Round7 | 30 |
| 51 | 51 | 1011 | Round1 | 27 |
| 115 | 51 | 1011 | Round2 | 45 |
| 179 | 51 | 1011 | Round3 | 36 |
| 243 | 51 | 1011 | Round4 | 57 |
| 307 | 51 | 1011 | Round5 | 32 |
| 371 | 51 | 1011 | Round6 | 47 |
| 435 | 51 | 1011 | Round7 | 33 |
| 52 | 52 | 935 | Round1 | 30 |
| 116 | 52 | 935 | Round2 | 22 |
| 180 | 52 | 935 | Round3 | 19 |
| 244 | 52 | 935 | Round4 | 48 |
| 308 | 52 | 935 | Round5 | 29 |
| 372 | 52 | 935 | Round6 | 35 |
| 436 | 52 | 935 | Round7 | 34 |
| 53 | 53 | 1393 | Round1 | NA |
| 117 | 53 | 1393 | Round2 | 25 |
| 181 | 53 | 1393 | Round3 | NA |
| 245 | 53 | 1393 | Round4 | 44 |
| 309 | 53 | 1393 | Round5 | NA |
| 373 | 53 | 1393 | Round6 | 57 |
| 437 | 53 | 1393 | Round7 | NA |
| 54 | 54 | 1270 | Round1 | 14 |
| 118 | 54 | 1270 | Round2 | 39 |
| 182 | 54 | 1270 | Round3 | 61 |
| 246 | 54 | 1270 | Round4 | NA |
| 310 | 54 | 1270 | Round5 | 15 |
| 374 | 54 | 1270 | Round6 | 59 |
| 438 | 54 | 1270 | Round7 | 64 |
| 55 | 55 | 1186 | Round1 | 62 |
| 119 | 55 | 1186 | Round2 | 31 |
| 183 | 55 | 1186 | Round3 | 10 |
| 247 | 55 | 1186 | Round4 | 30 |
| 311 | 55 | 1186 | Round5 | NA |
| 375 | 55 | 1186 | Round6 | 45 |
| 439 | 55 | 1186 | Round7 | 43 |
| 56 | 56 | 1153 | Round1 | NA |
| 120 | 56 | 1153 | Round2 | 11 |
| 184 | 56 | 1153 | Round3 | 35 |
| 248 | 56 | 1153 | Round4 | 45 |
| 312 | 56 | 1153 | Round5 | NA |
| 376 | 56 | 1153 | Round6 | 40 |
| 440 | 56 | 1153 | Round7 | 42 |
| 57 | 57 | 1092 | Round1 | 7 |
| 121 | 57 | 1092 | Round2 | 36 |
| 185 | 57 | 1092 | Round3 | 42 |
| 249 | 57 | 1092 | Round4 | 51 |
| 313 | 57 | 1092 | Round5 | 35 |
| 377 | 57 | 1092 | Round6 | 53 |
| 441 | 57 | 1092 | Round7 | NA |
| 58 | 58 | 917 | Round1 | 31 |
| 122 | 58 | 917 | Round2 | 2 |
| 186 | 58 | 917 | Round3 | 41 |
| 250 | 58 | 917 | Round4 | 23 |
| 314 | 58 | 917 | Round5 | 49 |
| 378 | 58 | 917 | Round6 | NA |
| 442 | 58 | 917 | Round7 | 45 |
| 59 | 59 | 853 | Round1 | 41 |
| 123 | 59 | 853 | Round2 | NA |
| 187 | 59 | 853 | Round3 | 9 |
| 251 | 59 | 853 | Round4 | 40 |
| 315 | 59 | 853 | Round5 | 43 |
| 379 | 59 | 853 | Round6 | 54 |
| 443 | 59 | 853 | Round7 | 44 |
| 60 | 60 | 967 | Round1 | 33 |
| 124 | 60 | 967 | Round2 | 34 |
| 188 | 60 | 967 | Round3 | 45 |
| 252 | 60 | 967 | Round4 | 42 |
| 316 | 60 | 967 | Round5 | 24 |
| 380 | 60 | 967 | Round6 | NA |
| 444 | 60 | 967 | Round7 | NA |
| 61 | 61 | 955 | Round1 | 32 |
| 125 | 61 | 955 | Round2 | 3 |
| 189 | 61 | 955 | Round3 | 54 |
| 253 | 61 | 955 | Round4 | 47 |
| 317 | 61 | 955 | Round5 | 42 |
| 381 | 61 | 955 | Round6 | 30 |
| 445 | 61 | 955 | Round7 | 37 |
| 62 | 62 | 1530 | Round1 | 55 |
| 126 | 62 | 1530 | Round2 | NA |
| 190 | 62 | 1530 | Round3 | NA |
| 254 | 62 | 1530 | Round4 | NA |
| 318 | 62 | 1530 | Round5 | NA |
| 382 | 62 | 1530 | Round6 | NA |
| 446 | 62 | 1530 | Round7 | NA |
| 63 | 63 | 1175 | Round1 | 2 |
| 127 | 63 | 1175 | Round2 | 48 |
| 191 | 63 | 1175 | Round3 | 49 |
| 255 | 63 | 1175 | Round4 | 43 |
| 319 | 63 | 1175 | Round5 | 45 |
| 383 | 63 | 1175 | Round6 | NA |
| 447 | 63 | 1175 | Round7 | NA |
| 64 | 64 | 1163 | Round1 | 22 |
| 128 | 64 | 1163 | Round2 | 30 |
| 192 | 64 | 1163 | Round3 | 31 |
| 256 | 64 | 1163 | Round4 | 49 |
| 320 | 64 | 1163 | Round5 | 46 |
| 384 | 64 | 1163 | Round6 | 42 |
| 448 | 64 | 1163 | Round7 | 54 |
#Query to achive the output using SQL
final_data <- sqldf("SELECT c.Player_Name
,c.State
,c.Total
,c.PreRtg
,p3.Oppo_PreRtg
FROM cleansed_data c
INNER JOIN (
SELECT p1.Pair,p1.PreRtg,avg(p2.PreRtg) AS Oppo_PreRtg
FROM (
SELECT * FROM agg_data
) p1
LEFT JOIN (
SELECT DISTINCT Pair,PreRtg
FROM agg_data
) p2 ON p1.value = p2.Pair
GROUP BY p1.Pair,p1.PreRtg
) p3 ON c.Pair = p3.Pair")
kable(data.frame(final_data)) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>%
row_spec(0, bold = T, color = "white", background = "#c65953") %>%
column_spec(5, background = "#f7f1e1") %>%
scroll_box(width = "100%", height = "400px")| Player_Name | State | Total | PreRtg | Oppo_PreRtg |
|---|---|---|---|---|
| GARY HUA | ON | 6.0 | 1794 | 1605.286 |
| DAKSHESH DARURI | MI | 6.0 | 1553 | 1469.286 |
| ADITYA BAJAJ | MI | 6.0 | 1384 | 1563.571 |
| PATRICK H SCHILLING | MI | 5.5 | 1716 | 1573.571 |
| HANSHI ZUO | MI | 5.5 | 1655 | 1500.857 |
| HANSEN SONG | OH | 5.0 | 1686 | 1518.714 |
| GARY DEE SWATHELL | MI | 5.0 | 1649 | 1372.143 |
| EZEKIEL HOUGHTON | MI | 5.0 | 1641 | 1468.429 |
| STEFANO LEE | ON | 5.0 | 1411 | 1523.143 |
| ANVIT RAO | MI | 5.0 | 1365 | 1554.143 |
| CAMERON WILLIAM MC LEMAN | MI | 4.5 | 1712 | 1467.571 |
| KENNETH J TACK | MI | 4.5 | 1663 | 1506.167 |
| TORRANCE HENRY JR | MI | 4.5 | 1666 | 1497.857 |
| BRADLEY SHAW | MI | 4.5 | 1610 | 1515.000 |
| ZACHARY JAMES HOUGHTON | MI | 4.5 | 1220 | 1483.857 |
| MIKE NIKITIN | MI | 4.0 | 1604 | 1385.800 |
| RONALD GRZEGORCZYK | MI | 4.0 | 1629 | 1498.571 |
| DAVID SUNDEEN | MI | 4.0 | 1600 | 1480.000 |
| DIPANKAR ROY | MI | 4.0 | 1564 | 1426.286 |
| JASON ZHENG | MI | 4.0 | 1595 | 1410.857 |
| DINH DANG BUI | ON | 4.0 | 1563 | 1470.429 |
| EUGENE L MCCLURE | MI | 4.0 | 1555 | 1300.333 |
| ALAN BUI | ON | 4.0 | 1363 | 1213.857 |
| MICHAEL R ALDRICH | MI | 4.0 | 1229 | 1357.000 |
| LOREN SCHWIEBERT | MI | 3.5 | 1745 | 1363.286 |
| MAX ZHU | ON | 3.5 | 1579 | 1506.857 |
| GAURAV GIDWANI | MI | 3.5 | 1552 | 1221.667 |
| SOFIA ADINA STANESCUBELLU | MI | 3.5 | 1507 | 1522.143 |
| CHIEDOZIE OKORIE | MI | 3.5 | 1602 | 1313.500 |
| GEORGE AVERY JONES | ON | 3.5 | 1522 | 1144.143 |
| RISHI SHETTY | MI | 3.5 | 1494 | 1259.857 |
| JOSHUA PHILIP MATHEWS | ON | 3.5 | 1441 | 1378.714 |
| JADE GE | MI | 3.5 | 1449 | 1276.857 |
| MICHAEL JEFFERY THOMAS | MI | 3.5 | 1399 | 1375.286 |
| JOSHUA DAVID LEE | MI | 3.5 | 1438 | 1149.714 |
| SIDDHARTH JHA | MI | 3.5 | 1355 | 1388.167 |
| AMIYATOSH PWNANANDAM | MI | 3.5 | 980 | 1384.800 |
| BRIAN LIU | MI | 3.0 | 1423 | 1539.167 |
| JOEL R HENDON | MI | 3.0 | 1436 | 1429.571 |
| FOREST ZHANG | MI | 3.0 | 1348 | 1390.571 |
| KYLE WILLIAM MURPHY | MI | 3.0 | 1403 | 1248.500 |
| JARED GE | MI | 3.0 | 1332 | 1149.857 |
| ROBERT GLEN VASEY | MI | 3.0 | 1283 | 1106.571 |
| JUSTIN D SCHILLING | MI | 3.0 | 1199 | 1327.000 |
| DEREK YAN | MI | 3.0 | 1242 | 1152.000 |
| JACOB ALEXANDER LAVALLEY | MI | 3.0 | 377 | 1357.714 |
| ERIC WRIGHT | MI | 2.5 | 1362 | 1392.000 |
| DANIEL KHAIN | MI | 2.5 | 1382 | 1355.800 |
| MICHAEL J MARTIN | MI | 2.5 | 1291 | 1285.800 |
| SHIVAM JHA | MI | 2.5 | 1056 | 1296.000 |
| TEJAS AYYAGARI | MI | 2.5 | 1011 | 1356.143 |
| ETHAN GUO | MI | 2.5 | 935 | 1494.571 |
| JOSE C YBARRA | MI | 2.0 | 1393 | 1345.333 |
| LARRY HODGE | MI | 2.0 | 1270 | 1206.167 |
| ALEX KONG | MI | 2.0 | 1186 | 1406.000 |
| MARISA RICCI | MI | 2.0 | 1153 | 1414.400 |
| MICHAEL LU | MI | 2.0 | 1092 | 1363.000 |
| VIRAJ MOHILE | MI | 2.0 | 917 | 1391.000 |
| SEAN M MC CORMICK | MI | 2.0 | 853 | 1319.000 |
| JULIA SHEN | MI | 1.5 | 967 | 1330.200 |
| JEZZEL FARKAS | ON | 1.5 | 955 | 1327.286 |
| ASHWIN BALAJI | MI | 1.0 | 1530 | 1186.000 |
| THOMAS JOSEPH HOSMER | MI | 1.0 | 1175 | 1350.200 |
| BEN LI | MI | 1.0 | 1163 | 1263.000 |
#Creating the .csv file
#Please change the working directory accordingly incase of writing in to local machine
setwd("C:/Users/aisha/Dropbox/CUNY/Semester1/DATA607_Data_Acquisition_and_Management/Week4")
write.csv(final_data,"tournament.csv")