2026-09-27

#Project 1

Approach

For this project, I will use the chess tournament data provided for the assignment. My goal is to clean the data and create a CSV file with information about each player.

First, I will read the tournament data into R and look at how the data is set and organized.

Next, I will find each player’s name, state, total points, pre tournament rating, and opponents.

Then, I will use the opponent numbers to find each opponent’s pre tournament rating. I will calculate the average opponent rating for each player. For example, Gary Hua’s average opponent rating is 1605.

Finally, I will create a clean table with the following items:

Player Name, State, Total Points, Pre Rating, and Average Opponent Pre Rating.

At last, I will check the results and save the final table as a CSV file.

Code Base

install.packages("pdftools", repos = "https://cloud.r-project.org")
## 
## The downloaded binary packages are in
##  /var/folders/q1/tz1y_jks4qdf2l6yq6z5wm_80000gn/T//RtmpqrQq98/downloaded_packages
library(pdftools)
## Warning: package 'pdftools' was built under R version 4.5.2
## Using poppler version 26.08.0
#Lets show PDF location on gitHub.
url <- "https://raw.githubusercontent.com/Maximus2485/Project-1-.DATA-607/main/Project%201%20dataset.tournamentinfo.pdf"
#Lets download PDF file
download.file(url, "Project 1 dataset.tournamentinfo.pdf", mode="wb")
# Lets read PDF
chess <- pdf_text("Project 1 dataset.tournamentinfo.pdf")
head(chess)
## [1] "9/23/26, 6:55 PM                      brightspace.cuny.edu/content/enforced/1404182-SPS01_DATA_607_1269_1_56662/tournamentinfo.txt?ou=1404182\n\n\n  -----------------------------------------------------------------------------------------\n   Pair | Player Name                     |Total|Round|Round|Round|Round|Round|Round|Round|\n   Num | USCF ID / Rtg (Pre->Post)        | Pts | 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n  -----------------------------------------------------------------------------------------\n      1 | GARY HUA                        |6.0 |W 39|W 21|W 18|W 14|W        7|D 12|D    4|\n     ON | 15445895 / R: 1794   ->1817     |N:2 |W     |B    |W    |B    |W    |B    |W    |\n  -----------------------------------------------------------------------------------------\n      2 | DAKSHESH DARURI                 |6.0 |W 63|W 58|L      4|W 17|W 16|W 20|W      7|\n     MI | 14598900 / R: 1553   ->1663     |N:2 |B     |W    |B    |W    |B    |W    |B    |\n  -----------------------------------------------------------------------------------------\n      3 | ADITYA BAJAJ                    |6.0 |L    8|W 61|W 25|W 21|W 11|W 13|W 12|\n     MI | 14959604 / R: 1384   ->1640     |N:2 |W     |B    |W    |B    |W    |B    |W    |\n  -----------------------------------------------------------------------------------------\n      4 | PATRICK H SCHILLING             |5.5 |W 23|D 28|W      2|W 26|D    5|W 19|D    1|\n     MI | 12616049 / R: 1716   ->1744     |N:2 |W     |B    |W    |B    |W    |B    |B    |\n  -----------------------------------------------------------------------------------------\n      5 | HANSHI ZUO                      |5.5 |W 45|W 37|D 12|D 13|D        4|W 14|W 17|\n     MI | 14601533 / R: 1655   ->1690     |N:2 |B     |W    |B    |W    |B    |W    |B    |\n  -----------------------------------------------------------------------------------------\n      6 | HANSEN SONG                     |5.0 |W 34|D 29|L 11|W 35|D 10|W 27|W 21|\n     OH | 15055204 / R: 1686   ->1687     |N:3 |W     |B    |W    |B    |B    |W    |B    |\n  -----------------------------------------------------------------------------------------\n      7 | GARY DEE SWATHELL               |5.0 |W 57|W 46|W 13|W 11|L        1|W   9|L   2|\n     MI | 11146376 / R: 1649   ->1673     |N:3 |W     |B    |W    |B    |B    |W    |W    |\n  -----------------------------------------------------------------------------------------\n      8 | EZEKIEL HOUGHTON                |5.0 |W    3|W 32|L 14|L     9|W 47|W 28|W 19|\n     MI | 15142253 / R: 1641P17->1657P24 |N:3 |B      |W    |B    |W    |B    |W    |W    |\n  -----------------------------------------------------------------------------------------\n      9 | STEFANO LEE                     |5.0 |W 25|L 18|W 59|W       8|W 26|L    7|W 20|\n     ON | 14954524 / R: 1411   ->1564     |N:2 |W     |B    |W    |B    |W    |B    |B    |\n  -----------------------------------------------------------------------------------------\n     10 | ANVIT RAO                       |5.0 |D 16|L 19|W 55|W 31|D        6|W 25|W 18|\n     MI | 14150362 / R: 1365   ->1544     |N:3 |W     |W    |B    |B    |W    |B    |W    |\n  -----------------------------------------------------------------------------------------\n     11 | CAMERON WILLIAM MC LEMAN        |4.5 |D 38|W 56|W      6|L   7|L   3|W 34|W 26|\n     MI | 12581589 / R: 1712   ->1696     |N:3 |B     |W    |B    |W    |B    |W    |B    |\n  -----------------------------------------------------------------------------------------\n     12 | KENNETH J TACK                  |4.5 |W 42|W 33|D      5|W 38|H     |D   1|L   3|\n     MI | 12681257 / R: 1663   ->1670     |N:3 |W     |B    |W    |B    |     |W    |B    |\n  -----------------------------------------------------------------------------------------\n     13 | TORRANCE HENRY JR               |4.5 |W 36|W 27|L      7|D   5|W 33|L    3|W 32|\n     MI | 15082995 / R: 1666   ->1662     |N:3 |B     |W    |B    |B    |W    |W    |B    |\n  -----------------------------------------------------------------------------------------\n     14 | BRADLEY SHAW                    |4.5 |W 54|W 44|W      8|L   1|D 27|L    5|W 31|\n     MI | 10131499 / R: 1610   ->1618     |N:3 |W     |B    |W    |W    |B    |B    |W    |\n  -----------------------------------------------------------------------------------------\n     15 | ZACHARY JAMES HOUGHTON          |4.5 |D 19|L 16|W 30|L 22|W 54|W 33|W 38|\n     MI | 15619130 / R: 1220P13->1416P20 |N:3 |B      |B    |W    |W    |B    |B    |W    |\n  -----------------------------------------------------------------------------------------\n     16 | MIKE NIKITIN                    |4.0 |D 10|W 15|H       |W 39|L    2|W 36|U     |\n     MI | 10295068 / R: 1604   ->1613     |N:3 |B     |W    |     |B    |W    |B    |     |\n  -----------------------------------------------------------------------------------------\n     17 | RONALD GRZEGORCZYK              |4.0 |W 48|W 41|L 26|L       2|W 23|W 22|L     5|\n     MI | 10297702 / R: 1629   ->1610     |N:3 |W     |B    |W    |B    |W    |B    |W    |\n  -----------------------------------------------------------------------------------------\n     18 | DAVID SUNDEEN                   |4.0 |W 47|W     9|L   1|W 32|L 19|W 38|L 10|\n     MI | 11342094 / R: 1600   ->1600     |N:3 |B     |W    |B    |W    |B    |W    |B    |\n  -----------------------------------------------------------------------------------------\n     19 | DIPANKAR ROY                    |4.0 |D 15|W 10|W 52|D 28|W 18|L         4|L   8|\n     MI | 14862333 / R: 1564   ->1570     |N:3 |W     |B    |W    |B    |W    |W    |B    |\n  -----------------------------------------------------------------------------------------\n     20 | JASON ZHENG                     |4.0 |L 40|W 49|W 23|W 41|W 28|L         2|L   9|\n     MI | 14529060 / R: 1595   ->1569     |N:4 |W     |B    |W    |B    |W    |B    |W    |\n  -----------------------------------------------------------------------------------------\n\nhttps://brightspace.cuny.edu/content/enforced/1404182-SPS01_DATA_607_1269_1_56662/tournamentinfo.txt?ou=1404182                                 1/4\n"                                                                   
## [2] "9/23/26, 6:55 PM                      brightspace.cuny.edu/content/enforced/1404182-SPS01_DATA_607_1269_1_56662/tournamentinfo.txt?ou=1404182\n     21 | DINH DANG BUI                   |4.0 |W 43|L     1|W 47|L    3|W 40|W 39|L     6|\n     ON | 15495066 / R: 1563P22->1562     |N:3 |B     |W    |B    |W    |W    |B    |W    |\n  -----------------------------------------------------------------------------------------\n     22 | EUGENE L MCCLURE                |4.0 |W 64|D 52|L 28|W 15|H         |L 17|W 40|\n     MI | 12405534 / R: 1555    ->1529    |N:4 |W     |B    |W    |B    |     |W    |B    |\n  -----------------------------------------------------------------------------------------\n     23 | ALAN BUI                        |4.0 |L    4|W 43|L 20|W 58|L 17|W 37|W 46|\n     ON | 15030142 / R: 1363    ->1371    |     |B    |W    |B    |W    |B    |W    |B    |\n  -----------------------------------------------------------------------------------------\n     24 | MICHAEL R ALDRICH               |4.0 |L 28|L 47|W 43|L 25|W 60|W 44|W 39|\n     MI | 13469010 / R: 1229    ->1300    |N:4 |B     |W    |B    |B    |W    |W    |B    |\n  -----------------------------------------------------------------------------------------\n     25 | LOREN SCHWIEBERT                |3.5 |L    9|W 53|L    3|W 24|D 34|L 10|W 47|\n     MI | 12486656 / R: 1745    ->1681    |N:4 |B     |W    |B    |W    |B    |W    |B    |\n  -----------------------------------------------------------------------------------------\n     26 | MAX ZHU                         |3.5 |W 49|W 40|W 17|L       4|L   9|D 32|L 11|\n     ON | 15131520 / R: 1579    ->1564    |N:4 |B     |W    |B    |W    |B    |W    |W    |\n  -----------------------------------------------------------------------------------------\n     27 | GAURAV GIDWANI                  |3.5 |W 51|L 13|W 46|W 37|D 14|L         6|U    |\n     MI | 14476567 / R: 1552    ->1539    |N:4 |W     |B    |W    |B    |W    |B    |     |\n  -----------------------------------------------------------------------------------------\n     28 | SOFIA ADINA STANESCU-BELLU      |3.5 |W 24|D     4|W 22|D 19|L 20|L      8|D 36|\n     MI | 14882954 / R: 1507    ->1513    |N:3 |W     |W    |B    |W    |B    |B    |W    |\n  -----------------------------------------------------------------------------------------\n     29 | CHIEDOZIE OKORIE                |3.5 |W 50|D     6|L 38|L 34|W 52|W 48|U        |\n     MI | 15323285 / R: 1602P6 ->1508P12 |N:4 |B      |W    |B    |W    |W    |B    |     |\n  -----------------------------------------------------------------------------------------\n     30 | GEORGE AVERY JONES              |3.5 |L 52|D 64|L 15|W 55|L 31|W 61|W 50|\n     ON | 12577178 / R: 1522    ->1444    |     |W    |B    |B    |W    |W    |B    |B    |\n  -----------------------------------------------------------------------------------------\n     31 | RISHI SHETTY                    |3.5 |L 58|D 55|W 64|L 10|W 30|W 50|L 14|\n     MI | 15131618 / R: 1494    ->1444    |     |B    |W    |B    |W    |B    |W    |B    |\n  -----------------------------------------------------------------------------------------\n     32 | JOSHUA PHILIP MATHEWS           |3.5 |W 61|L     8|W 44|L 18|W 51|D 26|L 13|\n     ON | 14073750 / R: 1441    ->1433    |N:4 |W     |B    |W    |B    |W    |B    |W    |\n  -----------------------------------------------------------------------------------------\n     33 | JADE GE                         |3.5 |W 60|L 12|W 50|D 36|L 13|L 15|W 51|\n     MI | 14691842 / R: 1449    ->1421    |     |B    |W    |B    |W    |B    |W    |B    |\n  -----------------------------------------------------------------------------------------\n     34 | MICHAEL JEFFERY THOMAS          |3.5 |L    6|W 60|L 37|W 29|D 25|L 11|W 52|\n     MI | 15051807 / R: 1399    ->1400    |     |B    |W    |B    |B    |W    |B    |W    |\n  -----------------------------------------------------------------------------------------\n     35 | JOSHUA DAVID LEE                |3.5 |L 46|L 38|W 56|L       6|W 57|D 52|W 48|\n     MI | 14601397 / R: 1438    ->1392    |     |W    |W    |B    |W    |B    |B    |W    |\n  -----------------------------------------------------------------------------------------\n     36 | SIDDHARTH JHA                   |3.5 |L 13|W 57|W 51|D 33|H         |L 16|D 28|\n     MI | 14773163 / R: 1355    ->1367    |N:4 |W     |B    |W    |B    |     |W    |B    |\n  -----------------------------------------------------------------------------------------\n     37 | AMIYATOSH PWNANANDAM            |3.5 |B     |L   5|W 34|L 27|H      |L 23|W 61|\n     MI | 15489571 / R: 980P12->1077P17 |       |     |B    |W    |W    |     |B    |W    |\n  -----------------------------------------------------------------------------------------\n     38 | BRIAN LIU                       |3.0 |D 11|W 35|W 29|L 12|H         |L 18|L 15|\n     MI | 15108523 / R: 1423    ->1439    |N:4 |W     |B    |W    |W    |     |B    |B    |\n  -----------------------------------------------------------------------------------------\n     39 | JOEL R HENDON                   |3.0 |L    1|W 54|W 40|L 16|W 44|L 21|L 24|\n     MI | 12923035 / R: 1436P23->1413     |N:4 |B     |W    |B    |W    |B    |W    |W    |\n  -----------------------------------------------------------------------------------------\n     40 | FOREST ZHANG                    |3.0 |W 20|L 26|L 39|W 59|L 21|W 56|L 22|\n     MI | 14892710 / R: 1348    ->1346    |     |B    |B    |W    |W    |B    |W    |W    |\n  -----------------------------------------------------------------------------------------\n     41 | KYLE WILLIAM MURPHY             |3.0 |W 59|L 17|W 58|L 20|X         |U    |U    |\n     MI | 15761443 / R: 1403P5 ->1341P9   |     |B    |W    |B    |W    |     |     |     |\n  -----------------------------------------------------------------------------------------\n     42 | JARED GE                        |3.0 |L 12|L 50|L 57|D 60|D 61|W 64|W 56|\n     MI | 14462326 / R: 1332    ->1256    |     |B    |W    |B    |B    |W    |W    |B    |\nhttps://brightspace.cuny.edu/content/enforced/1404182-SPS01_DATA_607_1269_1_56662/tournamentinfo.txt?ou=1404182                                 2/4\n"                 
## [3] "9/23/26, 6:55 PM                      brightspace.cuny.edu/content/enforced/1404182-SPS01_DATA_607_1269_1_56662/tournamentinfo.txt?ou=1404182\n  -----------------------------------------------------------------------------------------\n     43 | ROBERT GLEN VASEY               |3.0 |L 21|L 23|L 24|W 63|W 59|L 46|W 55|\n     MI | 14101068 / R: 1283   ->1244     |     |W    |B    |W    |W    |B    |B    |W    |\n  -----------------------------------------------------------------------------------------\n     44 | JUSTIN D SCHILLING              |3.0 |B     |L 14|L 32|W 53|L 39|L 24|W 59|\n     MI | 15323504 / R: 1199   ->1199     |     |     |W    |B    |B    |W    |B    |W    |\n  -----------------------------------------------------------------------------------------\n     45 | DEREK YAN                       |3.0 |L    5|L 51|D 60|L 56|W 63|D 55|W 58|\n     MI | 15372807 / R: 1242   ->1191     |     |W    |B    |W    |B    |W    |B    |W    |\n  -----------------------------------------------------------------------------------------\n     46 | JACOB ALEXANDER LAVALLEY        |3.0 |W 35|L     7|L 27|L 50|W 64|W 43|L 23|\n     MI | 15490981 / R: 377P3 ->1076P10 |       |B    |W    |B    |W    |B    |W    |W    |\n  -----------------------------------------------------------------------------------------\n     47 | ERIC WRIGHT                     |2.5 |L 18|W 24|L 21|W 61|L        8|D 51|L 25|\n     MI | 12533115 / R: 1362   ->1341     |     |W    |B    |W    |B    |W    |B    |W    |\n  -----------------------------------------------------------------------------------------\n     48 | DANIEL KHAIN                    |2.5 |L 17|W 63|H       |D 52|H     |L 29|L 35|\n     MI | 14369165 / R: 1382   ->1335     |     |B    |W    |     |B    |     |W    |B    |\n  -----------------------------------------------------------------------------------------\n     49 | MICHAEL J MARTIN                |2.5 |L 26|L 20|D 63|D 64|W 58|H          |U    |\n     MI | 12531685 / R: 1291P12->1259P17 |      |W    |W    |B    |W    |B    |     |     |\n  -----------------------------------------------------------------------------------------\n     50 | SHIVAM JHA                      |2.5 |L 29|W 42|L 33|W 46|H         |L 31|L 30|\n     MI | 14773178 / R: 1056   ->1111     |     |W    |B    |W    |B    |     |B    |W    |\n  -----------------------------------------------------------------------------------------\n     51 | TEJAS AYYAGARI                  |2.5 |L 27|W 45|L 36|W 57|L 32|D 47|L 33|\n     MI | 15205474 / R: 1011   ->1097     |     |B    |W    |B    |W    |B    |W    |W    |\n  -----------------------------------------------------------------------------------------\n     52 | ETHAN GUO                       |2.5 |W 30|D 22|L 19|D 48|L 29|D 35|L 34|\n     MI | 14918803 / R: 935    ->1092     |N:4 |B     |W    |B    |W    |B    |W    |B    |\n  -----------------------------------------------------------------------------------------\n     53 | JOSE C YBARRA                   |2.0 |H     |L 25|H     |L 44|U     |W 57|U     |\n     MI | 12578849 / R: 1393   ->1359     |     |     |B    |     |W    |     |W    |     |\n  -----------------------------------------------------------------------------------------\n     54 | LARRY HODGE                     |2.0 |L 14|L 39|L 61|B        |L 15|L 59|W 64|\n     MI | 12836773 / R: 1270   ->1200     |     |B    |B    |W    |     |W    |B    |W    |\n  -----------------------------------------------------------------------------------------\n     55 | ALEX KONG                       |2.0 |L 62|D 31|L 10|L 30|B         |D 45|L 43|\n     MI | 15412571 / R: 1186   ->1163     |     |W    |B    |W    |B    |     |W    |B    |\n  -----------------------------------------------------------------------------------------\n     56 | MARISA RICCI                    |2.0 |H     |L 11|L 35|W 45|H       |L 40|L 42|\n     MI | 14679887 / R: 1153   ->1140     |     |     |B    |W    |W    |     |B    |W    |\n  -----------------------------------------------------------------------------------------\n     57 | MICHAEL LU                      |2.0 |L    7|L 36|W 42|L 51|L 35|L 53|B         |\n     MI | 15113330 / R: 1092   ->1079     |     |B    |W    |W    |B    |W    |B    |     |\n  -----------------------------------------------------------------------------------------\n     58 | VIRAJ MOHILE                    |2.0 |W 31|L     2|L 41|L 23|L 49|B       |L 45|\n     MI | 14700365 / R: 917    -> 941     |     |W    |B    |W    |B    |W    |     |B    |\n  -----------------------------------------------------------------------------------------\n     59 | SEAN M MC CORMICK               |2.0 |L 41|B      |L   9|L 40|L 43|W 54|L 44|\n     MI | 12841036 / R: 853    -> 878     |     |W    |     |B    |B    |W    |W    |B    |\n  -----------------------------------------------------------------------------------------\n     60 | JULIA SHEN                      |1.5 |L 33|L 34|D 45|D 42|L 24|H          |U    |\n     MI | 14579262 / R: 967    -> 984     |     |W    |B    |B    |W    |B    |     |     |\n  -----------------------------------------------------------------------------------------\n     61 | JEZZEL FARKAS                   |1.5 |L 32|L     3|W 54|L 47|D 42|L 30|L 37|\n     ON | 15771592 / R: 955P11-> 979P18 |       |B    |W    |B    |W    |B    |W    |B    |\n  -----------------------------------------------------------------------------------------\n     62 | ASHWIN BALAJI                   |1.0 |W 55|U      |U    |U    |U    |U    |U    |\n     MI | 15219542 / R: 1530   ->1535     |     |B    |     |     |     |     |     |     |\n  -----------------------------------------------------------------------------------------\n     63 | THOMAS JOSEPH HOSMER            |1.0 |L    2|L 48|D 49|L 43|L 45|H        |U    |\n     MI | 15057092 / R: 1175   ->1125     |     |W    |B    |W    |B    |B    |     |     |\n  -----------------------------------------------------------------------------------------\n     64 | BEN LI                          |1.0 |L 22|D 30|L 31|D 49|L 46|L 42|L 54|\nhttps://brightspace.cuny.edu/content/enforced/1404182-SPS01_DATA_607_1269_1_56662/tournamentinfo.txt?ou=1404182                                 3/4\n"
## [4] "9/23/26, 6:55 PM                      brightspace.cuny.edu/content/enforced/1404182-SPS01_DATA_607_1269_1_56662/tournamentinfo.txt?ou=1404182\n     MI | 15006561 / R: 1163   ->1112     |     |B    |W    |W    |B    |W    |B    |B    |\n  -----------------------------------------------------------------------------------------\n\n\n\n\nhttps://brightspace.cuny.edu/content/enforced/1404182-SPS01_DATA_607_1269_1_56662/tournamentinfo.txt?ou=1404182                                 4/4\n"

Lets combine PDF pages

#Combine PDF pages
chess_text <- paste(chess, collapse="\n")
# Lets split the dataset into lines
chess_lines <- unlist(strsplit(chess_text, "\n"))
head(chess_lines, 20)
##  [1] "9/23/26, 6:55 PM                      brightspace.cuny.edu/content/enforced/1404182-SPS01_DATA_607_1269_1_56662/tournamentinfo.txt?ou=1404182"
##  [2] ""                                                                                                                                             
##  [3] ""                                                                                                                                             
##  [4] "  -----------------------------------------------------------------------------------------"                                                  
##  [5] "   Pair | Player Name                     |Total|Round|Round|Round|Round|Round|Round|Round|"                                                  
##  [6] "   Num | USCF ID / Rtg (Pre->Post)        | Pts | 1 | 2 | 3 | 4 | 5 | 6 | 7 |"                                                                
##  [7] "  -----------------------------------------------------------------------------------------"                                                  
##  [8] "      1 | GARY HUA                        |6.0 |W 39|W 21|W 18|W 14|W        7|D 12|D    4|"                                                  
##  [9] "     ON | 15445895 / R: 1794   ->1817     |N:2 |W     |B    |W    |B    |W    |B    |W    |"                                                  
## [10] "  -----------------------------------------------------------------------------------------"                                                  
## [11] "      2 | DAKSHESH DARURI                 |6.0 |W 63|W 58|L      4|W 17|W 16|W 20|W      7|"                                                  
## [12] "     MI | 14598900 / R: 1553   ->1663     |N:2 |B     |W    |B    |W    |B    |W    |B    |"                                                  
## [13] "  -----------------------------------------------------------------------------------------"                                                  
## [14] "      3 | ADITYA BAJAJ                    |6.0 |L    8|W 61|W 25|W 21|W 11|W 13|W 12|"                                                        
## [15] "     MI | 14959604 / R: 1384   ->1640     |N:2 |W     |B    |W    |B    |W    |B    |W    |"                                                  
## [16] "  -----------------------------------------------------------------------------------------"                                                  
## [17] "      4 | PATRICK H SCHILLING             |5.5 |W 23|D 28|W      2|W 26|D    5|W 19|D    1|"                                                  
## [18] "     MI | 12616049 / R: 1716   ->1744     |N:2 |W     |B    |W    |B    |W    |B    |B    |"                                                  
## [19] "  -----------------------------------------------------------------------------------------"                                                  
## [20] "      5 | HANSHI ZUO                      |5.5 |W 45|W 37|D 12|D 13|D        4|W 14|W 17|"
#Lets find player information in the lines having "I" and total number with a 
# decimal point
player_lines <- chess_lines[
  grepl("\\|", chess_lines) &
  grepl("[0-9]+\\.[0-9]", chess_lines)
]

# Check player lines
head(player_lines)
## [1] "      1 | GARY HUA                        |6.0 |W 39|W 21|W 18|W 14|W        7|D 12|D    4|"
## [2] "      2 | DAKSHESH DARURI                 |6.0 |W 63|W 58|L      4|W 17|W 16|W 20|W      7|"
## [3] "      3 | ADITYA BAJAJ                    |6.0 |L    8|W 61|W 25|W 21|W 11|W 13|W 12|"      
## [4] "      4 | PATRICK H SCHILLING             |5.5 |W 23|D 28|W      2|W 26|D    5|W 19|D    1|"
## [5] "      5 | HANSHI ZUO                      |5.5 |W 45|W 37|D 12|D 13|D        4|W 14|W 17|"  
## [6] "      6 | HANSEN SONG                     |5.0 |W 34|D 29|L 11|W 35|D 10|W 27|W 21|"

Lets find the rating/state lines

#Lets find the rating/state lines
rating_lines <- chess_lines[grep("R:", chess_lines)]
head(rating_lines)
## [1] "     ON | 15445895 / R: 1794   ->1817     |N:2 |W     |B    |W    |B    |W    |B    |W    |"
## [2] "     MI | 14598900 / R: 1553   ->1663     |N:2 |B     |W    |B    |W    |B    |W    |B    |"
## [3] "     MI | 14959604 / R: 1384   ->1640     |N:2 |W     |B    |W    |B    |W    |B    |W    |"
## [4] "     MI | 12616049 / R: 1716   ->1744     |N:2 |W     |B    |W    |B    |W    |B    |B    |"
## [5] "     MI | 14601533 / R: 1655   ->1690     |N:2 |B     |W    |B    |W    |B    |W    |B    |"
## [6] "     OH | 15055204 / R: 1686   ->1687     |N:3 |W     |B    |W    |B    |B    |W    |B    |"

Lets extract players names

#Lets extract players names
player_name <- sapply(
strsplit(player_lines, "\\|"),function(x) {
  trimws(x[2])
})
head(player_name)
## [1] "GARY HUA"            "DAKSHESH DARURI"     "ADITYA BAJAJ"       
## [4] "PATRICK H SCHILLING" "HANSHI ZUO"          "HANSEN SONG"

Lets extract total points

#Lets extract total points
points <- sapply(strsplit(player_lines, "\\|"), function(x) {
  as.numeric(trimws(x[3]))
})

points
##  [1] 6.0 6.0 6.0 5.5 5.5 5.0 5.0 5.0 5.0 5.0 4.5 4.5 4.5 4.5 4.5 4.0 4.0 4.0 4.0
## [20] 4.0 4.0 4.0 4.0 4.0 3.5 3.5 3.5 3.5 3.5 3.5 3.5 3.5 3.5 3.5 3.5 3.5 3.5 3.0
## [39] 3.0 3.0 3.0 3.0 3.0 3.0 3.0 3.0 2.5 2.5 2.5 2.5 2.5 2.5 2.0 2.0 2.0 2.0 2.0
## [58] 2.0 2.0 1.5 1.5 1.0 1.0 1.0

Lets extract state

#Lets extract state
state <- trimws(
  sub("\\|.*", "", rating_lines)
)
state
##  [1] "ON" "MI" "MI" "MI" "MI" "OH" "MI" "MI" "ON" "MI" "MI" "MI" "MI" "MI" "MI"
## [16] "MI" "MI" "MI" "MI" "MI" "ON" "MI" "ON" "MI" "MI" "ON" "MI" "MI" "MI" "ON"
## [31] "MI" "ON" "MI" "MI" "MI" "MI" "MI" "MI" "MI" "MI" "MI" "MI" "MI" "MI" "MI"
## [46] "MI" "MI" "MI" "MI" "MI" "MI" "MI" "MI" "MI" "MI" "MI" "MI" "MI" "MI" "MI"
## [61] "ON" "MI" "MI" "MI"

Lets extract pre-rating

#Lets extract pre-rating
pre_rating <- as.numeric(
  sub(".*R:\\s*([0-9]+).*", "\\1", rating_lines)
)
pre_rating
##  [1] 1794 1553 1384 1716 1655 1686 1649 1641 1411 1365 1712 1663 1666 1610 1220
## [16] 1604 1629 1600 1564 1595 1563 1555 1363 1229 1745 1579 1552 1507 1602 1522
## [31] 1494 1441 1449 1399 1438 1355  980 1423 1436 1348 1403 1332 1283 1199 1242
## [46]  377 1362 1382 1291 1056 1011  935 1393 1270 1186 1153 1092  917  853  967
## [61]  955 1530 1175 1163

Lets create the basic player table

#Lets create the basic player table
players <- data.frame(
  Player = player_name,
  State = state,
  Points = points,
  Pre_Rating = pre_rating
)
head(players)
##                Player State Points Pre_Rating
## 1            GARY HUA    ON    6.0       1794
## 2     DAKSHESH DARURI    MI    6.0       1553
## 3        ADITYA BAJAJ    MI    6.0       1384
## 4 PATRICK H SCHILLING    MI    5.5       1716
## 5          HANSHI ZUO    MI    5.5       1655
## 6         HANSEN SONG    OH    5.0       1686

Lets extract opponent numbers

#Lets extract opponent numbers
get_opponents <- function(x) {
  
  parts <- strsplit(x, "\\|")[[1]]
  
  rounds <- parts[4:length(parts)]
  
  opponents <- as.numeric(gsub("[^0-9]","", rounds)
                          
                          )
  
  opponents[!is.na(opponents)]
}
#Lets apply it to every player:
opponents <- lapply(player_lines, get_opponents)
opponents[[1]]
## [1] 39 21 18 14  7 12  4

Lets calculate average opponent pre-rating

#Lets calculate average opponent pre-rating
average_opponent_rating <- sapply(opponents, function(x) {
  mean(players$Pre_Rating[x],
       na.rm=TRUE )
})
#Add it to the table
players$Avg_Opponent_Rating <- round(average_opponent_rating)

#Check the final results
head(players)
##                Player State Points Pre_Rating Avg_Opponent_Rating
## 1            GARY HUA    ON    6.0       1794                1605
## 2     DAKSHESH DARURI    MI    6.0       1553                1469
## 3        ADITYA BAJAJ    MI    6.0       1384                1564
## 4 PATRICK H SCHILLING    MI    5.5       1716                1574
## 5          HANSHI ZUO    MI    5.5       1655                1501
## 6         HANSEN SONG    OH    5.0       1686                1519

Lets use SQLite

#Lets use SQLite
library(DBI)
## Warning: package 'DBI' was built under R version 4.5.2
library(RSQLite)
## Warning: package 'RSQLite' was built under R version 4.5.2
# Lets create database connection
con <- dbConnect(SQLite(), "Project 1 dataset.tournamentinfo.db")

# Lets put players data into SQL database
dbWriteTable(con, "players", players, overwrite = TRUE)

SQL Query

SELECT
    Player,
    State,
    Points,
    Pre_Rating,
    Avg_Opponent_Rating
FROM players;
Displaying records 1 - 10
Player State Points Pre_Rating Avg_Opponent_Rating
GARY HUA ON 6.0 1794 1605
DAKSHESH DARURI MI 6.0 1553 1469
ADITYA BAJAJ MI 6.0 1384 1564
PATRICK H SCHILLING MI 5.5 1716 1574
HANSHI ZUO MI 5.5 1655 1501
HANSEN SONG OH 5.0 1686 1519
GARY DEE SWATHELL MI 5.0 1649 1372
EZEKIEL HOUGHTON MI 5.0 1641 1468
STEFANO LEE ON 5.0 1411 1523
ANVIT RAO MI 5.0 1365 1554
#Lets export SQL results to CSV file
final_data <- dbGetQuery(
  con,"SELECT
    Player,
    State,
    Points,
    Pre_Rating,
    Avg_Opponent_Rating
FROM players"
)
write.csv(final_data, "chess_results.csv", row.names = FALSE)
dbDisconnect(con)

Conclusion

For this project, I used the chess tournament data provided for the assignment. My goal was to clean the data and create a CSV file with information about each chess player. First, I read the tournament data into R and look at how the data is set and organized. Then, I found each player’s name, state, total points, pre tournament rating, and opponents. Then, I used the opponent numbers to find each opponent’s pre tournament rating. The calculation of the average opponent rating for each player was done. For example, Gary Hua’s average opponent rating was 1605. Finally, the clean table was created with the following items: Player Name, State, Total Points, Pre Rating, and Average Opponent Pre Rating. Overall, I checked the results and saved the final table as a CSV file.

References

Google Deep Mind. (2026). Gemini 3 Flash [Large language model]. [https://gemini.google.com.%5D(https://gemini.google.com/ Accessed September 27th, 2026.

Wickham, H., Çetinkaya-Rundel, M., & Grolemund, G. (2023). R for data science (2nd ed.). O’Reilly Media. https://r4ds.hadley.nz/