Load Packages
Import Data
setwd("C:/Users/cassandra/Desktop/607")
chess <- read.csv("chess.txt")
Remove first two rows
chessnew <- chess[-c(1:2),]
Subsetting player info
name<-chessnew[seq(2, length(chessnew), 3)]
head(name,5)
## [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|
## 131 Levels: ----------------------------------------------------------------------------------------- ...
Subsetting rating info
rating<-chessnew[seq(3, length(chessnew), 3)]
head(rating,5)
## [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 |
## 131 Levels: ----------------------------------------------------------------------------------------- ...
Find average of opponent player rating
opporatingavg <- length(name)
for (i in 1:length(name))
{
opporatingavg[i] <- round(mean(prerating[as.numeric(unlist(opponentid[id[i]]))]), digits = 0)
}
Create dtaframe
chessdf <- data_frame(playername, state, totalpoint, prerating, opporatingavg)
Rename columns
colnames(chessdf) <- c("Player's Name", "Player's State", "Total Number of Points", "Player's Pre-Rating", "Opponents' Average Ratings")
chessdf
## # A tibble: 64 x 5
## `Player's Name` `Player's State` `Total Number o~ `Player's Pre-R~
## <chr> <chr> <dbl> <int>
## 1 GARY HUA ON 6 1794
## 2 DAKSHESH DARURI MI 6 1553
## 3 ADITYA BAJAJ MI 6 1384
## 4 PATRICK H SCHI~ MI 5.5 1716
## 5 HANSHI ZUO MI 5.5 1655
## 6 HANSEN SONG OH 5 1686
## 7 GARY DEE SWATH~ MI 5 1649
## 8 EZEKIEL HOUGHT~ MI 5 1641
## 9 STEFANO LEE ON 5 1411
## 10 ANVIT RAO MI 5 1365
## # ... with 54 more rows, and 1 more variable: `Opponents' Average
## # Ratings` <dbl>
Export csv file
write.csv(chessdf, file = "chessresults.csv")