This project is about R Character Manipulation and Data Processing. The file used for this purpose is a text file containing information on a Chess Tournmament. There are 64 cases/players and 10 attibutes used to make up the dataset.

Chess.txt file

Download text file here

This is the file that would be used to import into R, clean and extract useful data

This is the file that would be used to import into R, clean and extract useful data

Imported Text File

Here is what the file looks like when it was imported into R. It shows the first 10 cases of the text file. The data can be somewhat difficult to read the first time.

url <- "https://raw.githubusercontent.com/javernw/JWCUNYAssignments/master/Chess.txt"
chess <- read.csv(url, header = F, sep = "|", stringsAsFactors = FALSE)

head(chess, 10) #first 10 rows
##                                                                                           V1
## 1  -----------------------------------------------------------------------------------------
## 2                                                                                      Pair 
## 3                                                                                      Num  
## 4  -----------------------------------------------------------------------------------------
## 5                                                                                         1 
## 6                                                                                        ON 
## 7  -----------------------------------------------------------------------------------------
## 8                                                                                         2 
## 9                                                                                        MI 
## 10 -----------------------------------------------------------------------------------------
##                                   V2    V3    V4    V5    V6    V7    V8
## 1                                                                       
## 2   Player Name                      Total Round Round Round Round Round
## 3   USCF ID / Rtg (Pre->Post)         Pts    1     2     3     4     5  
## 4                                                                       
## 5   GARY HUA                         6.0   W  39 W  21 W  18 W  14 W   7
## 6   15445895 / R: 1794   ->1817      N:2   W     B     W     B     W    
## 7                                                                       
## 8   DAKSHESH DARURI                  6.0   W  63 W  58 L   4 W  17 W  16
## 9   14598900 / R: 1553   ->1663      N:2   B     W     B     W     B    
## 10                                                                      
##       V9   V10 V11
## 1               NA
## 2  Round Round  NA
## 3    6     7    NA
## 4               NA
## 5  D  12 D   4  NA
## 6  B     W      NA
## 7               NA
## 8  W  20 W   7  NA
## 9  W     B      NA
## 10              NA

Tidy Table

The table is conformed to a standard where you can understand the data.

#removing '-'s and '|'s from table and storing it as a data frame
chessData <- as.data.frame(sapply(chess, gsub, pattern = "[-]{2,}|[|]", replacement = ""))
#removing rows 1 to 4 and column 11 because of unnecessary data
chessData <- chessData[-c(1:4), -11] 
row.names(chessData) <- NULL # remove row number counts

#rename columns
colnames(chessData) <- c("Pair Num", "Player Name USCF ID / Rtg (Pre->Post)", "Total Num", "Round 1", "Round 2", "Round 3", "Round 4", "Round 5", "Round 6", "Round 7")

n <- nrow(chessData)
t <-seq(3, n, by = 3) #counts by 3 

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

Top 5 Players and their Opponents

1 Gary HUA

#if the variable is a factor it will be converted to character 
chessData %>% mutate_if(is.factor, as.character) -> chessData
## Warning: package 'bindrcpp' was built under R version 3.5.2
ghua <- chessData$`Player Name USCF ID / Rtg (Pre->Post)`[chessData$`Round 1` == "L   1"|chessData$`Round 2` == "L   1"|chessData$`Round 3` == "L   1"|chessData$`Round 4` == "L   1"|chessData$`Round 5` == "L   1"|chessData$`Round 6` == "L   1"|chessData$`Round 7` == "L   1" |chessData$`Round 1` == "D   1"|chessData$`Round 2` == "D   1"|chessData$`Round 3` == "D   1"|chessData$`Round 4` == "D   1"|chessData$`Round 5` == "D   1"|chessData$`Round 6` == "D   1"|chessData$`Round 7` == "D   1"|chessData$`Round 1` == "W   1"|chessData$`Round 2` == "W   1"|chessData$`Round 3`== "W   1"|chessData$`Round 4` == "W   1"|chessData$`Round 5` == "W   1"|chessData$`Round 6` == "W   1"|chessData$`Round 7` == "W   1"]

noquote(str_c(c(4, 7, 12, 14, 18, 21,39), ghua)) #attach player numbers
## [1] 4 PATRICK H SCHILLING               7 GARY DEE SWATHELL                
## [3] 12 KENNETH J TACK                   14 BRADLEY SHAW                    
## [5] 18 DAVID SUNDEEN                    21 DINH DANG BUI                   
## [7] 39 JOEL R HENDON

2 DAKSHESH DARURI

ddaruri <- chessData$`Player Name USCF ID / Rtg (Pre->Post)`[chessData$`Round 1` == "L   2"|chessData$`Round 2` == "L   2"|chessData$`Round 3` == "L   2"|chessData$`Round 4` == "L   2"|chessData$`Round 5` == "L   2"|chessData$`Round 6` == "L   2"|chessData$`Round 7` == "L   2" |chessData$`Round 1` == "D   2"|chessData$`Round 2` == "D   2"|chessData$`Round 3` == "D   2"|chessData$`Round 4` == "D   2"|chessData$`Round 5` == "D   2"|chessData$`Round 6` == "D   2"|chessData$`Round 7` == "D   2"|chessData$`Round 1` == "W   2"|chessData$`Round 2` == "W   2"|chessData$`Round 3`== "W   2"|chessData$`Round 4` == "W   2"|chessData$`Round 5` == "W   2"|chessData$`Round 6` == "W   2"|chessData$`Round 7` == "W   2"]

noquote(str_c(c(4, 7, 16, 17, 20, 58, 63), ddaruri))
## [1] 4 PATRICK H SCHILLING               7 GARY DEE SWATHELL                
## [3] 16 MIKE NIKITIN                     17 RONALD GRZEGORCZYK              
## [5] 20 JASON ZHENG                      58 VIRAJ MOHILE                    
## [7] 63 THOMAS JOSEPH HOSMER

3 ADITYA BAJAJ

abajaj<- chessData$`Player Name USCF ID / Rtg (Pre->Post)`[chessData$`Round 1` == "L   3"|chessData$`Round 2` == "L   3"|chessData$`Round 3` == "L   3"|chessData$`Round 4` == "L   3"|chessData$`Round 5` == "L   3"|chessData$`Round 6` == "L   3"|chessData$`Round 7` == "L   3" |chessData$`Round 1` == "D   3"|chessData$`Round 2` == "D   3"|chessData$`Round 3` == "D   3"|chessData$`Round 4` == "D   3"|chessData$`Round 5` == "D   3"|chessData$`Round 6` == "D   3"|chessData$`Round 7` == "D   3"|chessData$`Round 1` == "W   3"|chessData$`Round 2` == "W   3"|chessData$`Round 3`== "W   3"|chessData$`Round 4` == "W   3"|chessData$`Round 5` == "W   3"|chessData$`Round 6` == "W   3"|chessData$`Round 7` == "W   1"]

noquote(str_c(c(8, 11, 12, 13, 21, 25, 6), abajaj))
## [1] 8 EZEKIEL HOUGHTON                  11 CAMERON WILLIAM MC LEMAN        
## [3] 12 KENNETH J TACK                   13 TORRANCE HENRY JR               
## [5] 21 DINH DANG BUI                    25 LOREN SCHWIEBERT                
## [7] 6 JEZZEL FARKAS

4 PATRICK H SCHILLING

pschilling <- chessData$`Player Name USCF ID / Rtg (Pre->Post)`[chessData$`Round 1` == "L   4"|chessData$`Round 2` == "L   4"|chessData$`Round 3` == "L   4"|chessData$`Round 4` == "L   4"|chessData$`Round 5` == "L   4"|chessData$`Round 6` == "L   4"|chessData$`Round 7` == "L   4" |chessData$`Round 1` == "D   4"|chessData$`Round 2` == "D   4"|chessData$`Round 3` == "D   4"|chessData$`Round 4` == "D   4"|chessData$`Round 5` == "D   4"|chessData$`Round 6` == "D   4"|chessData$`Round 7` == "D   4"|chessData$`Round 1` == "W   4"|chessData$`Round 2` == "W   4"|chessData$`Round 3`== "W   4"|chessData$`Round 4` == "W   4"|chessData$`Round 5` == "W   4"|chessData$`Round 6` == "W   4"|chessData$`Round 7` == "W   4"]

noquote(str_c(c(1 ,2, 5, 19, 23, 26, 28), pschilling))
## [1] 1 GARY HUA                          2 DAKSHESH DARURI                  
## [3] 5 HANSHI ZUO                        19 DIPANKAR ROY                    
## [5] 23 ALAN BUI                         26 MAX ZHU                         
## [7] 28 SOFIA ADINA STANESCU-BELLU

5 HANSHI ZUO

hzuo <- chessData$`Player Name USCF ID / Rtg (Pre->Post)`[chessData$`Round 1` == "L   5"|chessData$`Round 2` == "L   5"|chessData$`Round 3` == "L   5"|chessData$`Round 4` == "L   5"|chessData$`Round 5` == "L   5"|chessData$`Round 6` == "L   5"|chessData$`Round 7` == "L   5" |chessData$`Round 1` == "D   5"|chessData$`Round 2` == "D   5"|chessData$`Round 3` == "D   5"|chessData$`Round 4` == "D   5"|chessData$`Round 5` == "D   5"|chessData$`Round 6` == "D   5"|chessData$`Round 7` == "D   5"|chessData$`Round 1` == "W   5"|chessData$`Round 2` == "W   5"|chessData$`Round 3`== "W   5"|chessData$`Round 4` == "W   5"|chessData$`Round 5` == "W   5"|chessData$`Round 6` == "W   5"|chessData$`Round 7` == "W   5"]

noquote(str_c(c(4, 12, 13, 14, 17, 37, 45), hzuo))
## [1] 4 PATRICK H SCHILLING               12 KENNETH J TACK                  
## [3] 13 TORRANCE HENRY JR                14 BRADLEY SHAW                    
## [5] 17 RONALD GRZEGORCZYK               37 AMIYATOSH PWNANANDAM            
## [7] 45 DEREK YAN

Result: Final Product

List of Chess players, their Points, Pre-Ratings and Average ratings of opponents from the tournaments.

The data was written to a .csv file. To see the file click this link

# Calculating average pre-ratings of each players' opponentsrs
p1avg <- round(mean(c(1436, 1563, 1600 ,1610 ,1649, 1663, 1716)))
p2avg <- round(mean(c(1175, 917, 1716, 1629, 1604, 1629, 1649)))
p3avg <- round(mean(c(1641, 955, 1745, 1563, 1712, 1666, 1663)))
p4avg <- round(mean(c(1363, 1507, 1553, 1579, 1655, 1564, 1794)))
p5avg <- round(mean(c(1242, 980, 1663, 1663, 1716, 1610, 1629)))
p6avg <- round(mean(c(1399, 1602, 1712, 1438, 1365, 1552, 1563)))
p7avg <- round(mean(c(1092, 377, 1666, 1712, 1794, 1411, 1553)))
p8avg <- round(mean(c(1384, 1441, 1610, 1411, 1362, 1507, 1564)))
p9avg <- round(mean(c(1745, 1600, 853, 1641, 1595 ,1649, 1579)))
p10avg <- round(mean(c(1604, 1564, 1186, 1494, 1686, 1745, 1600)))
p11avg <- round(mean(c(1423, 1153, 1686, 1673, 1384, 1399,1579)))
p12avg <- round(mean(c(1332, 1449, 1655, 1423, 1794, 1384)))
p13avg <- round(mean(c(1355, 1552, 1649, 1655,1449, 1384,1441)))
p14avg <- round(mean(c(1270, 1199, 1641, 1794, 1552, 1655, 1494)))
p15avg <- round(mean(c(1564, 1604, 1522, 1555, 1270, 1449, 1423)))
p16avg <- round(mean(c(1365, 1220, 1436, 1553, 1355)))
p17avg <- round(mean(c(1382, 1403, 1579, 1553, 1363, 1555,1655)))
p18avg <- round(mean(c(1362, 1411, 1794, 1441, 1564, 1423, 1365)))
p19avg <- round(mean(c(1220, 1365, 935, 1507, 1600, 1716, 1641)))
p20avg <- round(mean(c(1348, 1291, 1363, 1403, 1507, 1553, 1411)))
p21avg <- round(mean(c(1283, 1794, 1362, 1384, 1348, 1436, 1686)))
p22avg <- round(mean(c(1163, 935, 1507, 1220, 1629, 1348)))
p23avg <- round(mean(c(1716, 1283, 1595, 917, 1629, 980, 377)))
p24avg <- round(mean(c(1507, 1362, 1283, 1745, 967,1436, 1199)))
p25avg <- round(mean(c(1411, 1393, 1384, 1229, 1399, 1365, 1362)))
p26avg <- round(mean(c(1291, 1348, 1629, 1716, 1411, 1441, 1712)))
p27avg <- round(mean(c(1666, 1011, 377, 980, 1610, 1686)))
p28avg <- round(mean(c(1229, 1716, 1555, 1564, 1595, 1641, 1355)))
p29avg <- round(mean(c(1056, 1686, 1423, 1399, 935, 1382)))
p30avg <- round(mean(c(935, 1163, 1220, 1186, 1494, 955, 1056)))
p31avg <- round(mean(c(917, 1186, 1163, 1365, 1522, 1056, 1610)))
p32avg <- round(mean(c(955, 1641, 1199, 1600, 1011, 1579, 1666)))
p33avg <- round(mean(c(967, 1663, 1056, 1355, 1011, 1666, 1220)))
p34avg <- round(mean(c(1686, 967, 980, 1602, 1745, 1712, 935)))
p35avg <- round(mean(c(377, 1423, 1153, 1686, 1092, 935, 1382)))
p36avg <- round(mean(c(1666, 1092, 1011, 1449, 1604, 1507)))
p37avg <- round(mean(c(1655, 1399, 1552, 1363, 955)))
p38avg <- round(mean(c(1712, 1438, 1602, 1663, 1600, 1220)))
p39avg <- round(mean(c(1794, 1270, 1348, 1604, 1199, 1563, 1229)))
p40avg <- round(mean(c(1595, 1579, 1436, 853, 1563, 1153, 1555)))
p41avg <- round(mean(c(853, 1629, 917, 1595)))
p42avg <- round(mean(c(1663, 1056, 1092, 967, 955, 1163, 1153)))
p43avg <- round(mean(c(1563, 1363, 1229, 1175, 853, 377, 1186)))
p44avg <- round(mean(c(1610, 1441, 1393, 1436, 1229, 853)))
p45avg <- round(mean(c(1655, 1011, 967, 1153, 1175, 1186, 917)))
p46avg <- round(mean(c(1438, 1649, 1552, 1056, 1163, 1283, 1363)))
p47avg <- round(mean(c(1600, 1229, 1563, 955, 1641, 1011, 1745)))
p48avg <- round(mean(c(1629,1175, 935, 1602, 1438)))
p49avg <- round(mean(c(1579, 1595, 1175, 1163, 917)))
p50avg <- round(mean(c(1602, 1332, 1449, 377, 1494, 1522)))
p51avg <- round(mean(c(1552, 1242, 1355, 1092, 1441, 1362, 1449)))
p52avg <- round(mean(c(1522, 1555, 1564, 1382, 1602, 1438, 1399)))
p53avg <- round(mean(c(1745, 1199, 1092)))
p54avg <- round(mean(c(1610, 1436, 955, 1220, 853, 1163)))
p55avg <- round(mean(c(1530, 1494, 1365, 1242, 1283)))
p56avg <- round(mean(c(1712, 1438, 1242, 1348, 1332)))
p57avg <- round(mean(c(1649,1355, 1332, 1011,1438, 1393)))
p58avg <- round(mean(c(1602, 1553, 1403, 1363, 1291, 1242)))
p59avg <- round(mean(c(1403, 1411, 1348, 1283, 1270, 1199)))
p60avg <- round(mean(c(1449, 1399, 1242, 1332, 1229)))
p61avg <- round(mean(c(1441, 1384, 1270, 1362, 1332, 1522, 980)))
p62avg <- round(mean(c(1186)))
p63avg <- round(mean(c(1553, 1382, 1291, 1283, 1242)))
p64avg <- round(mean(c(1555,1522, 1494, 1291, 377, 1332, 1270)))


#Average pre-rating for each player
Avgprerating <- c(p1avg, p2avg, p3avg, p4avg, p5avg, p6avg, p7avg, p8avg, p9avg, p10avg, p11avg, p12avg, p13avg, p14avg, p15avg, p16avg, p17avg, p18avg, p19avg, p20avg, p21avg, p22avg, p23avg, p24avg, p25avg, p26avg, p27avg, p28avg, p29avg, p30avg, p31avg, p32avg, p33avg, p34avg, p35avg, p36avg, p37avg, p38avg, p39avg, p40avg, p41avg, p42avg, p43avg, p44avg, p45avg, p46avg, p47avg, p48avg, p49avg, p50avg, p51avg, p52avg, p53avg, p54avg, p55avg, p56avg, p57avg, p58avg, p59avg, p60avg, p61avg, p62avg, p63avg, p64avg)


#extract states
state <- unlist(str_extract_all(chessData$`Pair Num`, "[A-Z]{2}"))

#extract name of players
playernames <- unlist(str_extract_all(chessData$`Player Name USCF ID / Rtg (Pre->Post)`, "([A-Z]+ [ A-Z-]*)"))

#extract pre-rating scores
preRating <- unlist(str_extract_all(chessData$`Player Name USCF ID / Rtg (Pre->Post)`, "(: [0-9]{2,4})|  ([0-9]{3})"))
preRating <- gsub(": ", "", preRating)
preRating <- as.numeric(preRating)#convert from character to numeric

pointsnum <- unlist(str_extract_all(chessData$`Total Num`, "\\d\\.\\d"))
pointsnum <- as.numeric(pointsnum)#convert from character to numeric


#table of chess players, their scores and ratings
Chess <- data.frame(playernames, state, pointsnum, preRating, Avgprerating)
colnames(Chess) <- c("Player Names", "State", "Total Number of Points", "Pre Ratings", "Opponents Avg Chess Ratings")

#format table
Chess %>%
  kable() %>%
  kable_styling(font_size = 12)
Player Names State Total Number of Points Pre Ratings Opponents Avg Chess Ratings
GARY HUA ON 6.0 1794 1605
DAKSHESH DARURI MI 6.0 1553 1474
ADITYA BAJAJ MI 6.0 1384 1564
PATRICK H SCHILLING MI 5.5 1716 1574
HANSHI ZUO MI 5.5 1655 1500
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
CAMERON WILLIAM MC LEMAN MI 4.5 1712 1471
KENNETH J TACK MI 4.5 1663 1506
TORRANCE HENRY JR MI 4.5 1666 1498
BRADLEY SHAW MI 4.5 1610 1515
ZACHARY JAMES HOUGHTON MI 4.5 1220 1484
MIKE NIKITIN MI 4.0 1604 1386
RONALD GRZEGORCZYK MI 4.0 1629 1499
DAVID SUNDEEN MI 4.0 1600 1480
DIPANKAR ROY MI 4.0 1564 1426
JASON ZHENG MI 4.0 1595 1411
DINH DANG BUI ON 4.0 1563 1470
EUGENE L MCCLURE MI 4.0 1555 1300
ALAN BUI ON 4.0 1363 1214
MICHAEL R ALDRICH MI 4.0 1229 1357
LOREN SCHWIEBERT MI 3.5 1745 1363
MAX ZHU ON 3.5 1579 1507
GAURAV GIDWANI MI 3.5 1552 1222
SOFIA ADINA STANESCU-BELLU MI 3.5 1507 1522
CHIEDOZIE OKORIE MI 3.5 1602 1314
GEORGE AVERY JONES ON 3.5 1522 1144
RISHI SHETTY MI 3.5 1494 1260
JOSHUA PHILIP MATHEWS ON 3.5 1441 1379
JADE GE MI 3.5 1449 1277
MICHAEL JEFFERY THOMAS MI 3.5 1399 1375
JOSHUA DAVID LEE MI 3.5 1438 1150
SIDDHARTH JHA MI 3.5 1355 1388
AMIYATOSH PWNANANDAM MI 3.5 980 1385
BRIAN LIU MI 3.0 1423 1539
JOEL R HENDON MI 3.0 1436 1430
FOREST ZHANG MI 3.0 1348 1391
KYLE WILLIAM MURPHY MI 3.0 1403 1248
JARED GE MI 3.0 1332 1150
ROBERT GLEN VASEY MI 3.0 1283 1107
JUSTIN D SCHILLING MI 3.0 1199 1327
DEREK YAN MI 3.0 1242 1152
JACOB ALEXANDER LAVALLEY MI 3.0 377 1358
ERIC WRIGHT MI 2.5 1362 1392
DANIEL KHAIN MI 2.5 1382 1356
MICHAEL J MARTIN MI 2.5 1291 1286
SHIVAM JHA MI 2.5 1056 1296
TEJAS AYYAGARI MI 2.5 1011 1356
ETHAN GUO MI 2.5 935 1495
JOSE C YBARRA MI 2.0 1393 1345
LARRY HODGE MI 2.0 1270 1206
ALEX KONG MI 2.0 1186 1383
MARISA RICCI MI 2.0 1153 1414
MICHAEL LU MI 2.0 1092 1363
VIRAJ MOHILE MI 2.0 917 1409
SEAN M MC CORMICK MI 2.0 853 1319
JULIA SHEN MI 1.5 967 1330
JEZZEL FARKAS ON 1.5 955 1327
ASHWIN BALAJI MI 1.0 1530 1186
THOMAS JOSEPH HOSMER MI 1.0 1175 1350
BEN LI MI 1.0 1163 1263