Project One Requirements

In this project, you’re given a text file with chess tournament results where the information has some structure. Your job is to create an R Markdown file that generates a .CSV file (that could for example be imported into a SQL database) with the following information for all of the players:

Player’s Name, Player’s State, Total Number of Points, Player’s Pre-Rating, and Average Pre Chess Rating of Opponents. For the first player, the information would be:

Gary Hua, ON, 6.0, 1794, 1605. The 1605 was calculated by using the pre-tournament opponents’ ratings of 1436, 1563, 1600, 1610, 1649, 1663, 1716, and dividing by the total number of games played.

The chess rating system (invented by a Minnesota statistician named Arpad Elo) has been used in many other contexts, including assessing relative strength of employment candidates by human resource departments.

All of your code should be in an R markdown file (and published to rpubs.com); with your data accessible for the person running the script.

Background: In order to understand the problem and draw ideas on how to best work through the problem, I reviewed other similar works in RPubs as well as assigned readings and many tutorials on dplyr and stringr to understand how to apply concepts. I created my own version of explanatory notes and how to solve the problem.

First, we load appropriate libraries and import the dataset. We renamed the file “tournamentinfo” into an object labeled “Chess”. The first four rows of the dataset begins with a hyphenated line, the word “Pair”, the word “Num” and another a hyphenated line.

Global variables for CSV source and destination. To make it easier for future use, we’ll set global variables for the CSV source URL and full local path for the CSV file.

csv_url <- "https://raw.githubusercontent.com/professorfoy/DATA-607/main/tournamentinfo.txt"
csv_output_file <- "C:/Users/zengo/OneDrive/chess_ratings.csv"
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5     v purrr   0.3.4
## v tibble  3.1.4     v dplyr   1.0.7
## v tidyr   1.1.3     v stringr 1.4.0
## v readr   2.0.1     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(dplyr)
library(stringr)
library(ggplot2)
Chess <- read.csv(csv_url, header = FALSE)

View the variable names with the “str” command. Confirm that all 196 rows of data was imported.

str(Chess)
## 'data.frame':    196 obs. of  1 variable:
##  $ V1: chr  "-----------------------------------------------------------------------------------------" " Pair | Player Name                     |Total|Round|Round|Round|Round|Round|Round|Round| " " Num  | USCF ID / Rtg (Pre->Post)       | Pts |  1  |  2  |  3  |  4  |  5  |  6  |  7  | " "-----------------------------------------------------------------------------------------" ...

Once importation of the full dataset has been verified, the first four rows of the dataset must be removed as they will not be part of the analysis. To accomplish this, a new object is created labeled “Chess_2”.

Chess_2 <- Chess[-c(1:4),]

Once the first four rows of data have been removed, the data containing the Player’s Name, Player’s State, Total Number of Points, and Player’s Pre-Rating have to be isolated and unwanted symbols removed. We could further remove all the lines that are hyphenated, but it is more efficient to isolate the rows of desired data. To do this, we need to know the total length of the Chess_2 dataset. Since we removed the first four rows of data, the total length should be reduced to 192 rows, which will start with the player name. we ran the “str” function to verify that Chess_2 in fact has 192 rows of data remaining.

str(Chess_2)
##  chr [1:192] "    1 | GARY HUA                        |6.0  |W  39|W  21|W  18|W  14|W   7|D  12|D   4|" ...

Now that C verified the length of the dataset as having 192 rows, we can extract the rows with the data we am seeking. However, the dataset contains rows that have hyphenated lines across every 3rd row. To bypass the hyphenated lines, we created two objects to represent each row of data that is to be retained and pass them through a sequence command that will look for the row with the Player’s name, starting with the first row, skipping the 2nd and 3rd row, all the way through 192 rows. Another sequence command is given to look for the row with the Player’s state, starting with the second row, skipping the 1st and 3rd row, all the way through 192 rows.

Player_name_row <- Chess_2[seq(1, 192, 3)]
Player_state_row <- Chess_2[seq(2, 192, 3)]

To verify that these rows have been isolated, we passed each object through a head.matrix command to display all remaining rows.

head.matrix(Player_name_row)
##  [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|"
##  [7] "    7 | GARY DEE SWATHELL               |5.0  |W  57|W  46|W  13|W  11|L   1|W   9|L   2|"
##  [8] "    8 | EZEKIEL HOUGHTON                |5.0  |W   3|W  32|L  14|L   9|W  47|W  28|W  19|"
##  [9] "    9 | STEFANO LEE                     |5.0  |W  25|L  18|W  59|W   8|W  26|L   7|W  20|"
## [10] "   10 | ANVIT RAO                       |5.0  |D  16|L  19|W  55|W  31|D   6|W  25|W  18|"
## [11] "   11 | CAMERON WILLIAM MC LEMAN        |4.5  |D  38|W  56|W   6|L   7|L   3|W  34|W  26|"
## [12] "   12 | KENNETH J TACK                  |4.5  |W  42|W  33|D   5|W  38|H    |D   1|L   3|"
## [13] "   13 | TORRANCE HENRY JR               |4.5  |W  36|W  27|L   7|D   5|W  33|L   3|W  32|"
## [14] "   14 | BRADLEY SHAW                    |4.5  |W  54|W  44|W   8|L   1|D  27|L   5|W  31|"
## [15] "   15 | ZACHARY JAMES HOUGHTON          |4.5  |D  19|L  16|W  30|L  22|W  54|W  33|W  38|"
## [16] "   16 | MIKE NIKITIN                    |4.0  |D  10|W  15|H    |W  39|L   2|W  36|U    |"
## [17] "   17 | RONALD GRZEGORCZYK              |4.0  |W  48|W  41|L  26|L   2|W  23|W  22|L   5|"
## [18] "   18 | DAVID SUNDEEN                   |4.0  |W  47|W   9|L   1|W  32|L  19|W  38|L  10|"
## [19] "   19 | DIPANKAR ROY                    |4.0  |D  15|W  10|W  52|D  28|W  18|L   4|L   8|"
## [20] "   20 | JASON ZHENG                     |4.0  |L  40|W  49|W  23|W  41|W  28|L   2|L   9|"
## [21] "   21 | DINH DANG BUI                   |4.0  |W  43|L   1|W  47|L   3|W  40|W  39|L   6|"
## [22] "   22 | EUGENE L MCCLURE                |4.0  |W  64|D  52|L  28|W  15|H    |L  17|W  40|"
## [23] "   23 | ALAN BUI                        |4.0  |L   4|W  43|L  20|W  58|L  17|W  37|W  46|"
## [24] "   24 | MICHAEL R ALDRICH               |4.0  |L  28|L  47|W  43|L  25|W  60|W  44|W  39|"
## [25] "   25 | LOREN SCHWIEBERT                |3.5  |L   9|W  53|L   3|W  24|D  34|L  10|W  47|"
## [26] "   26 | MAX ZHU                         |3.5  |W  49|W  40|W  17|L   4|L   9|D  32|L  11|"
## [27] "   27 | GAURAV GIDWANI                  |3.5  |W  51|L  13|W  46|W  37|D  14|L   6|U    |"
## [28] "   28 | SOFIA ADINA STANESCU-BELLU      |3.5  |W  24|D   4|W  22|D  19|L  20|L   8|D  36|"
## [29] "   29 | CHIEDOZIE OKORIE                |3.5  |W  50|D   6|L  38|L  34|W  52|W  48|U    |"
## [30] "   30 | GEORGE AVERY JONES              |3.5  |L  52|D  64|L  15|W  55|L  31|W  61|W  50|"
## [31] "   31 | RISHI SHETTY                    |3.5  |L  58|D  55|W  64|L  10|W  30|W  50|L  14|"
## [32] "   32 | JOSHUA PHILIP MATHEWS           |3.5  |W  61|L   8|W  44|L  18|W  51|D  26|L  13|"
## [33] "   33 | JADE GE                         |3.5  |W  60|L  12|W  50|D  36|L  13|L  15|W  51|"
## [34] "   34 | MICHAEL JEFFERY THOMAS          |3.5  |L   6|W  60|L  37|W  29|D  25|L  11|W  52|"
## [35] "   35 | JOSHUA DAVID LEE                |3.5  |L  46|L  38|W  56|L   6|W  57|D  52|W  48|"
## [36] "   36 | SIDDHARTH JHA                   |3.5  |L  13|W  57|W  51|D  33|H    |L  16|D  28|"
## [37] "   37 | AMIYATOSH PWNANANDAM            |3.5  |B    |L   5|W  34|L  27|H    |L  23|W  61|"
## [38] "   38 | BRIAN LIU                       |3.0  |D  11|W  35|W  29|L  12|H    |L  18|L  15|"
## [39] "   39 | JOEL R HENDON                   |3.0  |L   1|W  54|W  40|L  16|W  44|L  21|L  24|"
## [40] "   40 | FOREST ZHANG                    |3.0  |W  20|L  26|L  39|W  59|L  21|W  56|L  22|"
## [41] "   41 | KYLE WILLIAM MURPHY             |3.0  |W  59|L  17|W  58|L  20|X    |U    |U    |"
## [42] "   42 | JARED GE                        |3.0  |L  12|L  50|L  57|D  60|D  61|W  64|W  56|"
## [43] "   43 | ROBERT GLEN VASEY               |3.0  |L  21|L  23|L  24|W  63|W  59|L  46|W  55|"
## [44] "   44 | JUSTIN D SCHILLING              |3.0  |B    |L  14|L  32|W  53|L  39|L  24|W  59|"
## [45] "   45 | DEREK YAN                       |3.0  |L   5|L  51|D  60|L  56|W  63|D  55|W  58|"
## [46] "   46 | JACOB ALEXANDER LAVALLEY        |3.0  |W  35|L   7|L  27|L  50|W  64|W  43|L  23|"
## [47] "   47 | ERIC WRIGHT                     |2.5  |L  18|W  24|L  21|W  61|L   8|D  51|L  25|"
## [48] "   48 | DANIEL KHAIN                    |2.5  |L  17|W  63|H    |D  52|H    |L  29|L  35|"
## [49] "   49 | MICHAEL J MARTIN                |2.5  |L  26|L  20|D  63|D  64|W  58|H    |U    |"
## [50] "   50 | SHIVAM JHA                      |2.5  |L  29|W  42|L  33|W  46|H    |L  31|L  30|"
## [51] "   51 | TEJAS AYYAGARI                  |2.5  |L  27|W  45|L  36|W  57|L  32|D  47|L  33|"
## [52] "   52 | ETHAN GUO                       |2.5  |W  30|D  22|L  19|D  48|L  29|D  35|L  34|"
## [53] "   53 | JOSE C YBARRA                   |2.0  |H    |L  25|H    |L  44|U    |W  57|U    |"
## [54] "   54 | LARRY HODGE                     |2.0  |L  14|L  39|L  61|B    |L  15|L  59|W  64|"
## [55] "   55 | ALEX KONG                       |2.0  |L  62|D  31|L  10|L  30|B    |D  45|L  43|"
## [56] "   56 | MARISA RICCI                    |2.0  |H    |L  11|L  35|W  45|H    |L  40|L  42|"
## [57] "   57 | MICHAEL LU                      |2.0  |L   7|L  36|W  42|L  51|L  35|L  53|B    |"
## [58] "   58 | VIRAJ MOHILE                    |2.0  |W  31|L   2|L  41|L  23|L  49|B    |L  45|"
## [59] "   59 | SEAN M MC CORMICK               |2.0  |L  41|B    |L   9|L  40|L  43|W  54|L  44|"
## [60] "   60 | JULIA SHEN                      |1.5  |L  33|L  34|D  45|D  42|L  24|H    |U    |"
## [61] "   61 | JEZZEL FARKAS                   |1.5  |L  32|L   3|W  54|L  47|D  42|L  30|L  37|"
## [62] "   62 | ASHWIN BALAJI                   |1.0  |W  55|U    |U    |U    |U    |U    |U    |"
## [63] "   63 | THOMAS JOSEPH HOSMER            |1.0  |L   2|L  48|D  49|L  43|L  45|H    |U    |"
## [64] "   64 | BEN LI                          |1.0  |L  22|D  30|L  31|D  49|L  46|L  42|L  54|"
head.matrix(Player_state_row)
##  [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    |"
##  [7] "   MI | 11146376 / R: 1649   ->1673     |N:3  |W    |B    |W    |B    |B    |W    |W    |"
##  [8] "   MI | 15142253 / R: 1641P17->1657P24  |N:3  |B    |W    |B    |W    |B    |W    |W    |"
##  [9] "   ON | 14954524 / R: 1411   ->1564     |N:2  |W    |B    |W    |B    |W    |B    |B    |"
## [10] "   MI | 14150362 / R: 1365   ->1544     |N:3  |W    |W    |B    |B    |W    |B    |W    |"
## [11] "   MI | 12581589 / R: 1712   ->1696     |N:3  |B    |W    |B    |W    |B    |W    |B    |"
## [12] "   MI | 12681257 / R: 1663   ->1670     |N:3  |W    |B    |W    |B    |     |W    |B    |"
## [13] "   MI | 15082995 / R: 1666   ->1662     |N:3  |B    |W    |B    |B    |W    |W    |B    |"
## [14] "   MI | 10131499 / R: 1610   ->1618     |N:3  |W    |B    |W    |W    |B    |B    |W    |"
## [15] "   MI | 15619130 / R: 1220P13->1416P20  |N:3  |B    |B    |W    |W    |B    |B    |W    |"
## [16] "   MI | 10295068 / R: 1604   ->1613     |N:3  |B    |W    |     |B    |W    |B    |     |"
## [17] "   MI | 10297702 / R: 1629   ->1610     |N:3  |W    |B    |W    |B    |W    |B    |W    |"
## [18] "   MI | 11342094 / R: 1600   ->1600     |N:3  |B    |W    |B    |W    |B    |W    |B    |"
## [19] "   MI | 14862333 / R: 1564   ->1570     |N:3  |W    |B    |W    |B    |W    |W    |B    |"
## [20] "   MI | 14529060 / R: 1595   ->1569     |N:4  |W    |B    |W    |B    |W    |B    |W    |"
## [21] "   ON | 15495066 / R: 1563P22->1562     |N:3  |B    |W    |B    |W    |W    |B    |W    |"
## [22] "   MI | 12405534 / R: 1555   ->1529     |N:4  |W    |B    |W    |B    |     |W    |B    |"
## [23] "   ON | 15030142 / R: 1363   ->1371     |     |B    |W    |B    |W    |B    |W    |B    |"
## [24] "   MI | 13469010 / R: 1229   ->1300     |N:4  |B    |W    |B    |B    |W    |W    |B    |"
## [25] "   MI | 12486656 / R: 1745   ->1681     |N:4  |B    |W    |B    |W    |B    |W    |B    |"
## [26] "   ON | 15131520 / R: 1579   ->1564     |N:4  |B    |W    |B    |W    |B    |W    |W    |"
## [27] "   MI | 14476567 / R: 1552   ->1539     |N:4  |W    |B    |W    |B    |W    |B    |     |"
## [28] "   MI | 14882954 / R: 1507   ->1513     |N:3  |W    |W    |B    |W    |B    |B    |W    |"
## [29] "   MI | 15323285 / R: 1602P6 ->1508P12  |N:4  |B    |W    |B    |W    |W    |B    |     |"
## [30] "   ON | 12577178 / R: 1522   ->1444     |     |W    |B    |B    |W    |W    |B    |B    |"
## [31] "   MI | 15131618 / R: 1494   ->1444     |     |B    |W    |B    |W    |B    |W    |B    |"
## [32] "   ON | 14073750 / R: 1441   ->1433     |N:4  |W    |B    |W    |B    |W    |B    |W    |"
## [33] "   MI | 14691842 / R: 1449   ->1421     |     |B    |W    |B    |W    |B    |W    |B    |"
## [34] "   MI | 15051807 / R: 1399   ->1400     |     |B    |W    |B    |B    |W    |B    |W    |"
## [35] "   MI | 14601397 / R: 1438   ->1392     |     |W    |W    |B    |W    |B    |B    |W    |"
## [36] "   MI | 14773163 / R: 1355   ->1367     |N:4  |W    |B    |W    |B    |     |W    |B    |"
## [37] "   MI | 15489571 / R:  980P12->1077P17  |     |     |B    |W    |W    |     |B    |W    |"
## [38] "   MI | 15108523 / R: 1423   ->1439     |N:4  |W    |B    |W    |W    |     |B    |B    |"
## [39] "   MI | 12923035 / R: 1436P23->1413     |N:4  |B    |W    |B    |W    |B    |W    |W    |"
## [40] "   MI | 14892710 / R: 1348   ->1346     |     |B    |B    |W    |W    |B    |W    |W    |"
## [41] "   MI | 15761443 / R: 1403P5 ->1341P9   |     |B    |W    |B    |W    |     |     |     |"
## [42] "   MI | 14462326 / R: 1332   ->1256     |     |B    |W    |B    |B    |W    |W    |B    |"
## [43] "   MI | 14101068 / R: 1283   ->1244     |     |W    |B    |W    |W    |B    |B    |W    |"
## [44] "   MI | 15323504 / R: 1199   ->1199     |     |     |W    |B    |B    |W    |B    |W    |"
## [45] "   MI | 15372807 / R: 1242   ->1191     |     |W    |B    |W    |B    |W    |B    |W    |"
## [46] "   MI | 15490981 / R:  377P3 ->1076P10  |     |B    |W    |B    |W    |B    |W    |W    |"
## [47] "   MI | 12533115 / R: 1362   ->1341     |     |W    |B    |W    |B    |W    |B    |W    |"
## [48] "   MI | 14369165 / R: 1382   ->1335     |     |B    |W    |     |B    |     |W    |B    |"
## [49] "   MI | 12531685 / R: 1291P12->1259P17  |     |W    |W    |B    |W    |B    |     |     |"
## [50] "   MI | 14773178 / R: 1056   ->1111     |     |W    |B    |W    |B    |     |B    |W    |"
## [51] "   MI | 15205474 / R: 1011   ->1097     |     |B    |W    |B    |W    |B    |W    |W    |"
## [52] "   MI | 14918803 / R:  935   ->1092     |N:4  |B    |W    |B    |W    |B    |W    |B    |"
## [53] "   MI | 12578849 / R: 1393   ->1359     |     |     |B    |     |W    |     |W    |     |"
## [54] "   MI | 12836773 / R: 1270   ->1200     |     |B    |B    |W    |     |W    |B    |W    |"
## [55] "   MI | 15412571 / R: 1186   ->1163     |     |W    |B    |W    |B    |     |W    |B    |"
## [56] "   MI | 14679887 / R: 1153   ->1140     |     |     |B    |W    |W    |     |B    |W    |"
## [57] "   MI | 15113330 / R: 1092   ->1079     |     |B    |W    |W    |B    |W    |B    |     |"
## [58] "   MI | 14700365 / R:  917   -> 941     |     |W    |B    |W    |B    |W    |     |B    |"
## [59] "   MI | 12841036 / R:  853   -> 878     |     |W    |     |B    |B    |W    |W    |B    |"
## [60] "   MI | 14579262 / R:  967   -> 984     |     |W    |B    |B    |W    |B    |     |     |"
## [61] "   ON | 15771592 / R:  955P11-> 979P18  |     |B    |W    |B    |W    |B    |W    |B    |"
## [62] "   MI | 15219542 / R: 1530   ->1535     |     |B    |     |     |     |     |     |     |"
## [63] "   MI | 15057092 / R: 1175   ->1125     |     |W    |B    |W    |B    |B    |     |     |"
## [64] "   MI | 15006561 / R: 1163   ->1112     |     |B    |W    |W    |B    |W    |B    |B    |"

The task is to extract the necessary data and avoid unwanted symbols across each row of data in the two objects. To extract the necessary data, we assigned new objects to each of the data fields that is required (Player’s Name, Player’s State, Total Number of Points, and Player’s Pre-Rating). We applied regular expression (regex) commands. We specifically used the str_extract(string, pattern) to create vectors for each object.

Extract Player’s Names and create the Player_Name object:

Player_Name <- str_extract(Player_name_row, "([a-zA-Z]+)\\s*([a-zA-Z]+)\\s*+([a-zA-Z]+)\\s*+([a-zA-Z]+)")
Player_Name
##  [1] "GARY HUA"                 "DAKSHESH DARURI"         
##  [3] "ADITYA BAJAJ"             "PATRICK H SCHILLING"     
##  [5] "HANSHI ZUO"               "HANSEN SONG"             
##  [7] "GARY DEE SWATHELL"        "EZEKIEL HOUGHTON"        
##  [9] "STEFANO LEE"              "ANVIT RAO"               
## [11] "CAMERON WILLIAM MC LEMAN" "KENNETH J TACK"          
## [13] "TORRANCE HENRY JR"        "BRADLEY SHAW"            
## [15] "ZACHARY JAMES HOUGHTON"   "MIKE NIKITIN"            
## [17] "RONALD GRZEGORCZYK"       "DAVID SUNDEEN"           
## [19] "DIPANKAR ROY"             "JASON ZHENG"             
## [21] "DINH DANG BUI"            "EUGENE L MCCLURE"        
## [23] "ALAN BUI"                 "MICHAEL R ALDRICH"       
## [25] "LOREN SCHWIEBERT"         "MAX ZHU"                 
## [27] "GAURAV GIDWANI"           "SOFIA ADINA STANESCU"    
## [29] "CHIEDOZIE OKORIE"         "GEORGE AVERY JONES"      
## [31] "RISHI SHETTY"             "JOSHUA PHILIP MATHEWS"   
## [33] "JADE GE"                  "MICHAEL JEFFERY THOMAS"  
## [35] "JOSHUA DAVID LEE"         "SIDDHARTH JHA"           
## [37] "AMIYATOSH PWNANANDAM"     "BRIAN LIU"               
## [39] "JOEL R HENDON"            "FOREST ZHANG"            
## [41] "KYLE WILLIAM MURPHY"      "JARED GE"                
## [43] "ROBERT GLEN VASEY"        "JUSTIN D SCHILLING"      
## [45] "DEREK YAN"                "JACOB ALEXANDER LAVALLEY"
## [47] "ERIC WRIGHT"              "DANIEL KHAIN"            
## [49] "MICHAEL J MARTIN"         "SHIVAM JHA"              
## [51] "TEJAS AYYAGARI"           "ETHAN GUO"               
## [53] "JOSE C YBARRA"            "LARRY HODGE"             
## [55] "ALEX KONG"                "MARISA RICCI"            
## [57] "MICHAEL LU"               "VIRAJ MOHILE"            
## [59] "SEAN M MC CORMICK"        "JULIA SHEN"              
## [61] "JEZZEL FARKAS"            "ASHWIN BALAJI"           
## [63] "THOMAS JOSEPH HOSMER"     "BEN LI"

Extract Player’s States and create the Player_State object:

Player_State <- str_extract(Player_state_row, "([a-zA-Z]+)")
Player_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"

Extract Player’s Total Number of Points and create the Player_Points object:

Player_Points <- str_extract(Player_name_row, "\\d.\\d")
Player_Points <- as.numeric(Player_Points)

# This next statement chains multiple functions together to extract each player's post rating.
# We have to account for the right-arrow with an optional space afterwards (e.g. -> 1672P234).
# Reading the statement from the inside out:
#   1. Extract all of the digits to the right of the right-arrow (str_extract)
#   2. Remove the white space and right-arrow (str_replace)
#   3. Convert the characters to integers (as.integer)
Player_PostRating <- as.integer(
                                  str_replace(
                                    str_extract(Player_state_row,"-> *(\\d+)"), 
                                    "-> *", "")
                                  )

Extract Player’s Player’s Pre-Rating - Part I. To extract the Player’s Pre-Rating, it required a two-step process. First, we created an object to isolate the Player_Pre-Rating ranking. To capture the data and not confound it with the Post-Rating, we extracted the R: with the Pre-Rating.

Player_PreRate <- str_extract(Player_state_row, "R:\\s*[[:digit:]]{3,}")
Player_PreRate
##  [1] "R: 1794" "R: 1553" "R: 1384" "R: 1716" "R: 1655" "R: 1686" "R: 1649"
##  [8] "R: 1641" "R: 1411" "R: 1365" "R: 1712" "R: 1663" "R: 1666" "R: 1610"
## [15] "R: 1220" "R: 1604" "R: 1629" "R: 1600" "R: 1564" "R: 1595" "R: 1563"
## [22] "R: 1555" "R: 1363" "R: 1229" "R: 1745" "R: 1579" "R: 1552" "R: 1507"
## [29] "R: 1602" "R: 1522" "R: 1494" "R: 1441" "R: 1449" "R: 1399" "R: 1438"
## [36] "R: 1355" "R:  980" "R: 1423" "R: 1436" "R: 1348" "R: 1403" "R: 1332"
## [43] "R: 1283" "R: 1199" "R: 1242" "R:  377" "R: 1362" "R: 1382" "R: 1291"
## [50] "R: 1056" "R: 1011" "R:  935" "R: 1393" "R: 1270" "R: 1186" "R: 1153"
## [57] "R: 1092" "R:  917" "R:  853" "R:  967" "R:  955" "R: 1530" "R: 1175"
## [64] "R: 1163"

Extract Player’s Player’s Pre-Rating - Part II. After extracting the R: with the Player’s Pre-Rating, we created another object, Player_PreRating2 to remove the R: and whitespace between ranking number. This procedure isolates the Pre-Rating.

Player_PreRating <- str_replace_all(Player_PreRate, "R:\\s", "")
Player_PreRating <- as.integer(Player_PreRating)
Player_PreRating
##  [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

Average Rating

In the Player_name_row dataset, each row records each win(W), lose(L) or draw(D), U or B against each opponent. The opponent has a corresponding list number in each row. Each W, L D U or B and opponent list number are separated by vertical pipes. For example, the format appears like this for a win against opponent 39 in the list: |W 39|. In the Player_state_row dataset, each opponent list number has an associated pre-player rating, which as been extracted as a list in the object Player_PreRating. To calculate the average rating for each opponent, we will need to isolate the opponent numbers in the Player_name_row dataset and match them with the list number in the Player_PreRating dataset. Then, create a new object that calculates the average for each row of data.

Since the format appears like this |(W)(L)(D)(U)(B) #| for each opponent in the list, an easy way to extract the opponent number is isolate the W, L D U or B, plus whitespace and player list number for each opponent and then remove the letters, plus whitespace.

opponent_list <- str_extract_all(Player_name_row, "\\|+\\w+\\s+.*")
opponent_list
## [[1]]
## [1] "|W  39|W  21|W  18|W  14|W   7|D  12|D   4|"
## 
## [[2]]
## [1] "|W  63|W  58|L   4|W  17|W  16|W  20|W   7|"
## 
## [[3]]
## [1] "|L   8|W  61|W  25|W  21|W  11|W  13|W  12|"
## 
## [[4]]
## [1] "|W  23|D  28|W   2|W  26|D   5|W  19|D   1|"
## 
## [[5]]
## [1] "|W  45|W  37|D  12|D  13|D   4|W  14|W  17|"
## 
## [[6]]
## [1] "|W  34|D  29|L  11|W  35|D  10|W  27|W  21|"
## 
## [[7]]
## [1] "|W  57|W  46|W  13|W  11|L   1|W   9|L   2|"
## 
## [[8]]
## [1] "|W   3|W  32|L  14|L   9|W  47|W  28|W  19|"
## 
## [[9]]
## [1] "|W  25|L  18|W  59|W   8|W  26|L   7|W  20|"
## 
## [[10]]
## [1] "|D  16|L  19|W  55|W  31|D   6|W  25|W  18|"
## 
## [[11]]
## [1] "|D  38|W  56|W   6|L   7|L   3|W  34|W  26|"
## 
## [[12]]
## [1] "|W  42|W  33|D   5|W  38|H    |D   1|L   3|"
## 
## [[13]]
## [1] "|W  36|W  27|L   7|D   5|W  33|L   3|W  32|"
## 
## [[14]]
## [1] "|W  54|W  44|W   8|L   1|D  27|L   5|W  31|"
## 
## [[15]]
## [1] "|D  19|L  16|W  30|L  22|W  54|W  33|W  38|"
## 
## [[16]]
## [1] "|D  10|W  15|H    |W  39|L   2|W  36|U    |"
## 
## [[17]]
## [1] "|W  48|W  41|L  26|L   2|W  23|W  22|L   5|"
## 
## [[18]]
## [1] "|W  47|W   9|L   1|W  32|L  19|W  38|L  10|"
## 
## [[19]]
## [1] "|D  15|W  10|W  52|D  28|W  18|L   4|L   8|"
## 
## [[20]]
## [1] "|L  40|W  49|W  23|W  41|W  28|L   2|L   9|"
## 
## [[21]]
## [1] "|W  43|L   1|W  47|L   3|W  40|W  39|L   6|"
## 
## [[22]]
## [1] "|W  64|D  52|L  28|W  15|H    |L  17|W  40|"
## 
## [[23]]
## [1] "|L   4|W  43|L  20|W  58|L  17|W  37|W  46|"
## 
## [[24]]
## [1] "|L  28|L  47|W  43|L  25|W  60|W  44|W  39|"
## 
## [[25]]
## [1] "|L   9|W  53|L   3|W  24|D  34|L  10|W  47|"
## 
## [[26]]
## [1] "|W  49|W  40|W  17|L   4|L   9|D  32|L  11|"
## 
## [[27]]
## [1] "|W  51|L  13|W  46|W  37|D  14|L   6|U    |"
## 
## [[28]]
## [1] "|W  24|D   4|W  22|D  19|L  20|L   8|D  36|"
## 
## [[29]]
## [1] "|W  50|D   6|L  38|L  34|W  52|W  48|U    |"
## 
## [[30]]
## [1] "|L  52|D  64|L  15|W  55|L  31|W  61|W  50|"
## 
## [[31]]
## [1] "|L  58|D  55|W  64|L  10|W  30|W  50|L  14|"
## 
## [[32]]
## [1] "|W  61|L   8|W  44|L  18|W  51|D  26|L  13|"
## 
## [[33]]
## [1] "|W  60|L  12|W  50|D  36|L  13|L  15|W  51|"
## 
## [[34]]
## [1] "|L   6|W  60|L  37|W  29|D  25|L  11|W  52|"
## 
## [[35]]
## [1] "|L  46|L  38|W  56|L   6|W  57|D  52|W  48|"
## 
## [[36]]
## [1] "|L  13|W  57|W  51|D  33|H    |L  16|D  28|"
## 
## [[37]]
## [1] "|B    |L   5|W  34|L  27|H    |L  23|W  61|"
## 
## [[38]]
## [1] "|D  11|W  35|W  29|L  12|H    |L  18|L  15|"
## 
## [[39]]
## [1] "|L   1|W  54|W  40|L  16|W  44|L  21|L  24|"
## 
## [[40]]
## [1] "|W  20|L  26|L  39|W  59|L  21|W  56|L  22|"
## 
## [[41]]
## [1] "|W  59|L  17|W  58|L  20|X    |U    |U    |"
## 
## [[42]]
## [1] "|L  12|L  50|L  57|D  60|D  61|W  64|W  56|"
## 
## [[43]]
## [1] "|L  21|L  23|L  24|W  63|W  59|L  46|W  55|"
## 
## [[44]]
## [1] "|B    |L  14|L  32|W  53|L  39|L  24|W  59|"
## 
## [[45]]
## [1] "|L   5|L  51|D  60|L  56|W  63|D  55|W  58|"
## 
## [[46]]
## [1] "|W  35|L   7|L  27|L  50|W  64|W  43|L  23|"
## 
## [[47]]
## [1] "|L  18|W  24|L  21|W  61|L   8|D  51|L  25|"
## 
## [[48]]
## [1] "|L  17|W  63|H    |D  52|H    |L  29|L  35|"
## 
## [[49]]
## [1] "|L  26|L  20|D  63|D  64|W  58|H    |U    |"
## 
## [[50]]
## [1] "|L  29|W  42|L  33|W  46|H    |L  31|L  30|"
## 
## [[51]]
## [1] "|L  27|W  45|L  36|W  57|L  32|D  47|L  33|"
## 
## [[52]]
## [1] "|W  30|D  22|L  19|D  48|L  29|D  35|L  34|"
## 
## [[53]]
## [1] "|H    |L  25|H    |L  44|U    |W  57|U    |"
## 
## [[54]]
## [1] "|L  14|L  39|L  61|B    |L  15|L  59|W  64|"
## 
## [[55]]
## [1] "|L  62|D  31|L  10|L  30|B    |D  45|L  43|"
## 
## [[56]]
## [1] "|H    |L  11|L  35|W  45|H    |L  40|L  42|"
## 
## [[57]]
## [1] "|L   7|L  36|W  42|L  51|L  35|L  53|B    |"
## 
## [[58]]
## [1] "|W  31|L   2|L  41|L  23|L  49|B    |L  45|"
## 
## [[59]]
## [1] "|L  41|B    |L   9|L  40|L  43|W  54|L  44|"
## 
## [[60]]
## [1] "|L  33|L  34|D  45|D  42|L  24|H    |U    |"
## 
## [[61]]
## [1] "|L  32|L   3|W  54|L  47|D  42|L  30|L  37|"
## 
## [[62]]
## [1] "|W  55|U    |U    |U    |U    |U    |U    |"
## 
## [[63]]
## [1] "|L   2|L  48|D  49|L  43|L  45|H    |U    |"
## 
## [[64]]
## [1] "|L  22|D  30|L  31|D  49|L  46|L  42|L  54|"

After the zeros have been inserted, we removed the letters, whitespace and vertical pipes to isolate just the opponent list number. We labeled a new object, “opponent_list2” to represent the opponents list numbers. Each round now has a number associated with it to show who are the opponents or zero if there were no opponents (players may have dropped out of the tournament).

opponent_list2 <- str_extract_all(opponent_list, "\\d+")
opponent_list2
## [[1]]
## [1] "39" "21" "18" "14" "7"  "12" "4" 
## 
## [[2]]
## [1] "63" "58" "4"  "17" "16" "20" "7" 
## 
## [[3]]
## [1] "8"  "61" "25" "21" "11" "13" "12"
## 
## [[4]]
## [1] "23" "28" "2"  "26" "5"  "19" "1" 
## 
## [[5]]
## [1] "45" "37" "12" "13" "4"  "14" "17"
## 
## [[6]]
## [1] "34" "29" "11" "35" "10" "27" "21"
## 
## [[7]]
## [1] "57" "46" "13" "11" "1"  "9"  "2" 
## 
## [[8]]
## [1] "3"  "32" "14" "9"  "47" "28" "19"
## 
## [[9]]
## [1] "25" "18" "59" "8"  "26" "7"  "20"
## 
## [[10]]
## [1] "16" "19" "55" "31" "6"  "25" "18"
## 
## [[11]]
## [1] "38" "56" "6"  "7"  "3"  "34" "26"
## 
## [[12]]
## [1] "42" "33" "5"  "38" "1"  "3" 
## 
## [[13]]
## [1] "36" "27" "7"  "5"  "33" "3"  "32"
## 
## [[14]]
## [1] "54" "44" "8"  "1"  "27" "5"  "31"
## 
## [[15]]
## [1] "19" "16" "30" "22" "54" "33" "38"
## 
## [[16]]
## [1] "10" "15" "39" "2"  "36"
## 
## [[17]]
## [1] "48" "41" "26" "2"  "23" "22" "5" 
## 
## [[18]]
## [1] "47" "9"  "1"  "32" "19" "38" "10"
## 
## [[19]]
## [1] "15" "10" "52" "28" "18" "4"  "8" 
## 
## [[20]]
## [1] "40" "49" "23" "41" "28" "2"  "9" 
## 
## [[21]]
## [1] "43" "1"  "47" "3"  "40" "39" "6" 
## 
## [[22]]
## [1] "64" "52" "28" "15" "17" "40"
## 
## [[23]]
## [1] "4"  "43" "20" "58" "17" "37" "46"
## 
## [[24]]
## [1] "28" "47" "43" "25" "60" "44" "39"
## 
## [[25]]
## [1] "9"  "53" "3"  "24" "34" "10" "47"
## 
## [[26]]
## [1] "49" "40" "17" "4"  "9"  "32" "11"
## 
## [[27]]
## [1] "51" "13" "46" "37" "14" "6" 
## 
## [[28]]
## [1] "24" "4"  "22" "19" "20" "8"  "36"
## 
## [[29]]
## [1] "50" "6"  "38" "34" "52" "48"
## 
## [[30]]
## [1] "52" "64" "15" "55" "31" "61" "50"
## 
## [[31]]
## [1] "58" "55" "64" "10" "30" "50" "14"
## 
## [[32]]
## [1] "61" "8"  "44" "18" "51" "26" "13"
## 
## [[33]]
## [1] "60" "12" "50" "36" "13" "15" "51"
## 
## [[34]]
## [1] "6"  "60" "37" "29" "25" "11" "52"
## 
## [[35]]
## [1] "46" "38" "56" "6"  "57" "52" "48"
## 
## [[36]]
## [1] "13" "57" "51" "33" "16" "28"
## 
## [[37]]
## [1] "5"  "34" "27" "23" "61"
## 
## [[38]]
## [1] "11" "35" "29" "12" "18" "15"
## 
## [[39]]
## [1] "1"  "54" "40" "16" "44" "21" "24"
## 
## [[40]]
## [1] "20" "26" "39" "59" "21" "56" "22"
## 
## [[41]]
## [1] "59" "17" "58" "20"
## 
## [[42]]
## [1] "12" "50" "57" "60" "61" "64" "56"
## 
## [[43]]
## [1] "21" "23" "24" "63" "59" "46" "55"
## 
## [[44]]
## [1] "14" "32" "53" "39" "24" "59"
## 
## [[45]]
## [1] "5"  "51" "60" "56" "63" "55" "58"
## 
## [[46]]
## [1] "35" "7"  "27" "50" "64" "43" "23"
## 
## [[47]]
## [1] "18" "24" "21" "61" "8"  "51" "25"
## 
## [[48]]
## [1] "17" "63" "52" "29" "35"
## 
## [[49]]
## [1] "26" "20" "63" "64" "58"
## 
## [[50]]
## [1] "29" "42" "33" "46" "31" "30"
## 
## [[51]]
## [1] "27" "45" "36" "57" "32" "47" "33"
## 
## [[52]]
## [1] "30" "22" "19" "48" "29" "35" "34"
## 
## [[53]]
## [1] "25" "44" "57"
## 
## [[54]]
## [1] "14" "39" "61" "15" "59" "64"
## 
## [[55]]
## [1] "62" "31" "10" "30" "45" "43"
## 
## [[56]]
## [1] "11" "35" "45" "40" "42"
## 
## [[57]]
## [1] "7"  "36" "42" "51" "35" "53"
## 
## [[58]]
## [1] "31" "2"  "41" "23" "49" "45"
## 
## [[59]]
## [1] "41" "9"  "40" "43" "54" "44"
## 
## [[60]]
## [1] "33" "34" "45" "42" "24"
## 
## [[61]]
## [1] "32" "3"  "54" "47" "42" "30" "37"
## 
## [[62]]
## [1] "55"
## 
## [[63]]
## [1] "2"  "48" "49" "43" "45"
## 
## [[64]]
## [1] "22" "30" "31" "49" "46" "42" "54"

With the opponent list numbers isolated in new object labeled opponent_list2, the goal is to calculate the prerating rating of each player’s opponents.

Specifically, since opponent_list2 is a list of character vectors (see below):

[[1]] “39” “21” “18” “14” “7” “12” “4”

[[2]] “63” “58” “4” “17” “16” “20” “7” . . .

For index [[1]], iterate through each element and find the opponent_rating: “39” “21” “18” “14” “7” “12” “4” -> 1436 1563 1600 1610 1649 1663 1716

And then calculate the mean(1436, 1563, 1600, 1610, 1649, 1663, 1716) = 1605.

Repeat the above steps through the rest of the opponent_list2.

# Initialize a vector of opponent ratings and player expected ratings
Average_PreChess_Rating_Opponent <- c()

# We'll also calculate a player's expected rating
Player_ExpPoints <- c()

# Iterate through the opponent_list2 by index
for (player_index in 1:length(opponent_list2)) {
  # Initialize temporary vector to hold the opponent ratings
  opponent_ratings <- c()

  # Iterate through every opponent_list2 vector
  # We also convert the character vector to integers
  for (s in as.integer(opponent_list2[[player_index]])) {
    opponent_ratings <- append(opponent_ratings, as.integer(Player_PreRating[[s]]))
  }
  # Remember to round the mean to zero decimal places
  average_opponent_prechess_rating = round(mean(opponent_ratings))[1]
  
  # Expected rating for the player to one significant digit
  # Reference:
  #   - https://chess.stackexchange.com/questions/18209/how-do-you-calculate-your-tournament-performance-rating
  #   - https://docs.google.com/spreadsheets/d/19yWu1PxCDwx0phTqeoKzdyP21FiRUgNfp6B6vktSND0/copy
  expected_points = 1/(10^((mean(opponent_ratings) - Player_PreRating[player_index])/400)+1) * length(opponent_ratings)
  expected_points = round( expected_points, 1 )
  
  # Save the results
  Average_PreChess_Rating_Opponent <- append(Average_PreChess_Rating_Opponent, average_opponent_prechess_rating)
  Player_ExpPoints <- append(Player_ExpPoints, expected_points)
  
}
Average_PreChess_Rating_Opponent
##  [1] 1605 1469 1564 1574 1501 1519 1372 1468 1523 1554 1468 1506 1498 1515 1484
## [16] 1386 1499 1480 1426 1411 1470 1300 1214 1357 1363 1507 1222 1522 1314 1144
## [31] 1260 1379 1277 1375 1150 1388 1385 1539 1430 1391 1248 1150 1107 1327 1152
## [46] 1358 1392 1356 1286 1296 1356 1495 1345 1206 1406 1414 1363 1391 1319 1330
## [61] 1327 1186 1350 1263
Player_ExpPoints
##  [1] 5.2 4.3 1.8 4.9 5.0 5.1 5.8 5.1 2.4 1.8 5.6 4.3 5.1 4.4 1.3 3.9 4.8 4.7 4.8
## [20] 5.2 4.4 4.9 4.9 2.3 6.3 4.2 5.2 3.3 5.0 6.3 5.6 4.1 5.1 3.7 5.9 2.7 0.4 2.0
## [39] 3.6 3.1 2.8 5.2 5.1 1.9 4.4 0.0 3.2 2.7 2.5 1.2 0.8 0.3 1.7 3.5 1.3 0.9 1.0
## [58] 0.4 0.4 0.5 0.7 0.9 1.3 2.5

Finally, we create the CSV dataframe:

csv <- data.frame(Player_Name, Player_State, Player_Points, Player_ExpPoints, Player_PreRating, Player_PostRating,Average_PreChess_Rating_Opponent)
csv <- csv %>%
  mutate (PointDifferential = Player_Points - Player_ExpPoints)
csv <- csv %>%
  mutate (RatingDifferential = Player_PostRating - Player_PreRating)

# Write the csv to a file
write_csv(csv, csv_output_file)

csv
##                 Player_Name Player_State Player_Points Player_ExpPoints
## 1                  GARY HUA           ON           6.0              5.2
## 2           DAKSHESH DARURI           MI           6.0              4.3
## 3              ADITYA BAJAJ           MI           6.0              1.8
## 4       PATRICK H SCHILLING           MI           5.5              4.9
## 5                HANSHI ZUO           MI           5.5              5.0
## 6               HANSEN SONG           OH           5.0              5.1
## 7         GARY DEE SWATHELL           MI           5.0              5.8
## 8          EZEKIEL HOUGHTON           MI           5.0              5.1
## 9               STEFANO LEE           ON           5.0              2.4
## 10                ANVIT RAO           MI           5.0              1.8
## 11 CAMERON WILLIAM MC LEMAN           MI           4.5              5.6
## 12           KENNETH J TACK           MI           4.5              4.3
## 13        TORRANCE HENRY JR           MI           4.5              5.1
## 14             BRADLEY SHAW           MI           4.5              4.4
## 15   ZACHARY JAMES HOUGHTON           MI           4.5              1.3
## 16             MIKE NIKITIN           MI           4.0              3.9
## 17       RONALD GRZEGORCZYK           MI           4.0              4.8
## 18            DAVID SUNDEEN           MI           4.0              4.7
## 19             DIPANKAR ROY           MI           4.0              4.8
## 20              JASON ZHENG           MI           4.0              5.2
## 21            DINH DANG BUI           ON           4.0              4.4
## 22         EUGENE L MCCLURE           MI           4.0              4.9
## 23                 ALAN BUI           ON           4.0              4.9
## 24        MICHAEL R ALDRICH           MI           4.0              2.3
## 25         LOREN SCHWIEBERT           MI           3.5              6.3
## 26                  MAX ZHU           ON           3.5              4.2
## 27           GAURAV GIDWANI           MI           3.5              5.2
## 28     SOFIA ADINA STANESCU           MI           3.5              3.3
## 29         CHIEDOZIE OKORIE           MI           3.5              5.0
## 30       GEORGE AVERY JONES           ON           3.5              6.3
## 31             RISHI SHETTY           MI           3.5              5.6
## 32    JOSHUA PHILIP MATHEWS           ON           3.5              4.1
## 33                  JADE GE           MI           3.5              5.1
## 34   MICHAEL JEFFERY THOMAS           MI           3.5              3.7
## 35         JOSHUA DAVID LEE           MI           3.5              5.9
## 36            SIDDHARTH JHA           MI           3.5              2.7
## 37     AMIYATOSH PWNANANDAM           MI           3.5              0.4
## 38                BRIAN LIU           MI           3.0              2.0
## 39            JOEL R HENDON           MI           3.0              3.6
## 40             FOREST ZHANG           MI           3.0              3.1
## 41      KYLE WILLIAM MURPHY           MI           3.0              2.8
## 42                 JARED GE           MI           3.0              5.2
## 43        ROBERT GLEN VASEY           MI           3.0              5.1
## 44       JUSTIN D SCHILLING           MI           3.0              1.9
## 45                DEREK YAN           MI           3.0              4.4
## 46 JACOB ALEXANDER LAVALLEY           MI           3.0              0.0
## 47              ERIC WRIGHT           MI           2.5              3.2
## 48             DANIEL KHAIN           MI           2.5              2.7
## 49         MICHAEL J MARTIN           MI           2.5              2.5
## 50               SHIVAM JHA           MI           2.5              1.2
## 51           TEJAS AYYAGARI           MI           2.5              0.8
## 52                ETHAN GUO           MI           2.5              0.3
## 53            JOSE C YBARRA           MI           2.0              1.7
## 54              LARRY HODGE           MI           2.0              3.5
## 55                ALEX KONG           MI           2.0              1.3
## 56             MARISA RICCI           MI           2.0              0.9
## 57               MICHAEL LU           MI           2.0              1.0
## 58             VIRAJ MOHILE           MI           2.0              0.4
## 59        SEAN M MC CORMICK           MI           2.0              0.4
## 60               JULIA SHEN           MI           1.5              0.5
## 61            JEZZEL FARKAS           ON           1.5              0.7
## 62            ASHWIN BALAJI           MI           1.0              0.9
## 63     THOMAS JOSEPH HOSMER           MI           1.0              1.3
## 64                   BEN LI           MI           1.0              2.5
##    Player_PreRating Player_PostRating Average_PreChess_Rating_Opponent
## 1              1794              1817                             1605
## 2              1553              1663                             1469
## 3              1384              1640                             1564
## 4              1716              1744                             1574
## 5              1655              1690                             1501
## 6              1686              1687                             1519
## 7              1649              1673                             1372
## 8              1641              1657                             1468
## 9              1411              1564                             1523
## 10             1365              1544                             1554
## 11             1712              1696                             1468
## 12             1663              1670                             1506
## 13             1666              1662                             1498
## 14             1610              1618                             1515
## 15             1220              1416                             1484
## 16             1604              1613                             1386
## 17             1629              1610                             1499
## 18             1600              1600                             1480
## 19             1564              1570                             1426
## 20             1595              1569                             1411
## 21             1563              1562                             1470
## 22             1555              1529                             1300
## 23             1363              1371                             1214
## 24             1229              1300                             1357
## 25             1745              1681                             1363
## 26             1579              1564                             1507
## 27             1552              1539                             1222
## 28             1507              1513                             1522
## 29             1602              1508                             1314
## 30             1522              1444                             1144
## 31             1494              1444                             1260
## 32             1441              1433                             1379
## 33             1449              1421                             1277
## 34             1399              1400                             1375
## 35             1438              1392                             1150
## 36             1355              1367                             1388
## 37              980              1077                             1385
## 38             1423              1439                             1539
## 39             1436              1413                             1430
## 40             1348              1346                             1391
## 41             1403              1341                             1248
## 42             1332              1256                             1150
## 43             1283              1244                             1107
## 44             1199              1199                             1327
## 45             1242              1191                             1152
## 46              377              1076                             1358
## 47             1362              1341                             1392
## 48             1382              1335                             1356
## 49             1291              1259                             1286
## 50             1056              1111                             1296
## 51             1011              1097                             1356
## 52              935              1092                             1495
## 53             1393              1359                             1345
## 54             1270              1200                             1206
## 55             1186              1163                             1406
## 56             1153              1140                             1414
## 57             1092              1079                             1363
## 58              917               941                             1391
## 59              853               878                             1319
## 60              967               984                             1330
## 61              955               979                             1327
## 62             1530              1535                             1186
## 63             1175              1125                             1350
## 64             1163              1112                             1263
##    PointDifferential RatingDifferential
## 1                0.8                 23
## 2                1.7                110
## 3                4.2                256
## 4                0.6                 28
## 5                0.5                 35
## 6               -0.1                  1
## 7               -0.8                 24
## 8               -0.1                 16
## 9                2.6                153
## 10               3.2                179
## 11              -1.1                -16
## 12               0.2                  7
## 13              -0.6                 -4
## 14               0.1                  8
## 15               3.2                196
## 16               0.1                  9
## 17              -0.8                -19
## 18              -0.7                  0
## 19              -0.8                  6
## 20              -1.2                -26
## 21              -0.4                 -1
## 22              -0.9                -26
## 23              -0.9                  8
## 24               1.7                 71
## 25              -2.8                -64
## 26              -0.7                -15
## 27              -1.7                -13
## 28               0.2                  6
## 29              -1.5                -94
## 30              -2.8                -78
## 31              -2.1                -50
## 32              -0.6                 -8
## 33              -1.6                -28
## 34              -0.2                  1
## 35              -2.4                -46
## 36               0.8                 12
## 37               3.1                 97
## 38               1.0                 16
## 39              -0.6                -23
## 40              -0.1                 -2
## 41               0.2                -62
## 42              -2.2                -76
## 43              -2.1                -39
## 44               1.1                  0
## 45              -1.4                -51
## 46               3.0                699
## 47              -0.7                -21
## 48              -0.2                -47
## 49               0.0                -32
## 50               1.3                 55
## 51               1.7                 86
## 52               2.2                157
## 53               0.3                -34
## 54              -1.5                -70
## 55               0.7                -23
## 56               1.1                -13
## 57               1.0                -13
## 58               1.6                 24
## 59               1.6                 25
## 60               1.0                 17
## 61               0.8                 24
## 62               0.1                  5
## 63              -0.3                -50
## 64              -1.5                -51

Plots

Histogram
ggplot(data = csv, aes(x=Player_PreRating)) + geom_histogram(binwidth=25)

ggplot(data = csv, aes(x=Player_PostRating)) + geom_histogram(binwidth=25)

##### Boxplot 
ggplot(data = csv, aes(y=Player_PreRating)) + geom_boxplot()

##### Scatter plot, color by state
ggplot(data = csv, aes(x=Player_PostRating, y=Player_Points, color=Player_State)) + geom_point()