library(readr)
chess <- read_file("https://raw.githubusercontent.com/swigodsky/DATA-607/master/tournamentinfo.txt")
library(stringr)
name <- unlist(str_extract_all(chess, "[[:upper:]]{2,} ?[[:upper:]]{1,} ?[[:upper:]]{1,} ?-?[[:upper:]]{1,}"))
name = name[-1]
head(name)
## [1] "GARY HUA" "DAKSHESH DARURI" "ADITYA BAJAJ"
## [4] "PATRICK H SCHILLING" "HANSHI ZUO" "HANSEN SONG"
state <- unlist(str_extract_all(chess, "\n [[:upper:]]{2}"))
state <- unlist(str_extract_all(state, "[[:upper:]]{2}"))
head(state)
## [1] "ON" "MI" "MI" "MI" "MI" "OH"
totalpnts <- unlist(str_extract_all(chess, "[[:digit:]]{1}\\.[[:digit:]]{1}"))
head(totalpnts)
## [1] "6.0" "6.0" "6.0" "5.5" "5.5" "5.0"
prerating <- unlist(str_extract_all(chess, "R: *[[:digit:]]{1,}"))
prerating <- as.numeric(unlist(str_extract_all(prerating, "[[:digit:]]{1,}")))
head(prerating)
## [1] 1794 1553 1384 1716 1655 1686
oppnum <- unlist(str_extract_all(chess, "W *[[:digit:]]{1,}|D *[[:digit:]]{1,}|L *[[:digit:]]{1,}|\n"))
oppnum <- unlist(str_extract_all(oppnum, "\n|[[:digit:]]{1,}"))
oppnum = oppnum[-1:-4]
oppnumdigit <- str_detect(oppnum, "[[:digit:]]{1,}")
x <- 1
y <- 1
a <-c(NA,NA)
opponent <- data.frame(list("Opponent 1"=a, "Opponent 2"=a, "Opponent 3"=a,"Opponent 4"=a,"Opponent 5"=a,"Opponent 6"=a, "Opponent 7"=a), stringsAsFactors = FALSE)
for (i in 1:length(oppnum)){
ifelse ((oppnumdigit[i] == TRUE),
{opponent[x,y] <- oppnum[i]
y <- y+1},
{x <- x + 1
y <- 1})
}
opponent <- opponent[!((is.na(opponent$Opponent.1)==TRUE & is.na(opponent$Opponent.2)==TRUE & is.na(opponent$Opponent.3)==TRUE & is.na(opponent$Opponent.4)==TRUE & is.na(opponent$Opponent.5)==TRUE & is.na(opponent$Opponent.6)==TRUE & is.na(opponent$Opponent.7)==TRUE)),]
head(opponent)
## Opponent.1 Opponent.2 Opponent.3 Opponent.4 Opponent.5 Opponent.6
## 1 39 21 18 14 7 12
## 4 63 58 4 17 16 20
## 7 8 61 25 21 11 13
## 10 23 28 2 26 5 19
## 13 45 37 12 13 4 14
## 16 34 29 11 35 10 27
## Opponent.7
## 1 4
## 4 7
## 7 12
## 10 1
## 13 17
## 16 21
opponent_rating <- data.frame(stringsAsFactors = FALSE)
for (i in 1:64){
opponent_rating <- rbind (opponent_rating, c(prerating[as.numeric(opponent[i,])]))
}
opponent_rating <- cbind(opponent_rating, rowMeans(opponent_rating, na.rm = TRUE))
colnames(opponent_rating) <- c("Opponent 1", "Opponent 2", "Opponent 3", "Opponent 4", "Opponent 5", "Opponent 6", "Opponent 7", "Average Opponent Rating")
head(opponent_rating)
## Opponent 1 Opponent 2 Opponent 3 Opponent 4 Opponent 5 Opponent 6
## 1 1436 1563 1600 1610 1649 1663
## 2 1175 917 1716 1629 1604 1595
## 3 1641 955 1745 1563 1712 1666
## 4 1363 1507 1553 1579 1655 1564
## 5 1242 980 1663 1666 1716 1610
## 6 1399 1602 1712 1438 1365 1552
## Opponent 7 Average Opponent Rating
## 1 1716 1605.286
## 2 1649 1469.286
## 3 1663 1563.571
## 4 1794 1573.571
## 5 1629 1500.857
## 6 1563 1518.714
info_table <- data.frame(list(name, state, totalpnts, prerating, opponent_rating$`Average Opponent Rating`))
colnames(info_table) <- c("Name", "State", "Total Points", "Prerating", "Avg Opponent Rating")
info_table
## Name State Total Points Prerating
## 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
## 7 GARY DEE SWATHELL MI 5.0 1649
## 8 EZEKIEL HOUGHTON MI 5.0 1641
## 9 STEFANO LEE ON 5.0 1411
## 10 ANVIT RAO MI 5.0 1365
## 11 CAMERON WILLIAM MC LEMAN MI 4.5 1712
## 12 KENNETH J TACK MI 4.5 1663
## 13 TORRANCE HENRY JR MI 4.5 1666
## 14 BRADLEY SHAW MI 4.5 1610
## 15 ZACHARY JAMES HOUGHTON MI 4.5 1220
## 16 MIKE NIKITIN MI 4.0 1604
## 17 RONALD GRZEGORCZYK MI 4.0 1629
## 18 DAVID SUNDEEN MI 4.0 1600
## 19 DIPANKAR ROY MI 4.0 1564
## 20 JASON ZHENG MI 4.0 1595
## 21 DINH DANG BUI ON 4.0 1563
## 22 EUGENE L MCCLURE MI 4.0 1555
## 23 ALAN BUI ON 4.0 1363
## 24 MICHAEL R ALDRICH MI 4.0 1229
## 25 LOREN SCHWIEBERT MI 3.5 1745
## 26 MAX ZHU ON 3.5 1579
## 27 GAURAV GIDWANI MI 3.5 1552
## 28 SOFIA ADINA STANESCU-BELLU MI 3.5 1507
## 29 CHIEDOZIE OKORIE MI 3.5 1602
## 30 GEORGE AVERY JONES ON 3.5 1522
## 31 RISHI SHETTY MI 3.5 1494
## 32 JOSHUA PHILIP MATHEWS ON 3.5 1441
## 33 JADE GE MI 3.5 1449
## 34 MICHAEL JEFFERY THOMAS MI 3.5 1399
## 35 JOSHUA DAVID LEE MI 3.5 1438
## 36 SIDDHARTH JHA MI 3.5 1355
## 37 AMIYATOSH PWNANANDAM MI 3.5 980
## 38 BRIAN LIU MI 3.0 1423
## 39 JOEL R HENDON MI 3.0 1436
## 40 FOREST ZHANG MI 3.0 1348
## 41 KYLE WILLIAM MURPHY MI 3.0 1403
## 42 JARED GE MI 3.0 1332
## 43 ROBERT GLEN VASEY MI 3.0 1283
## 44 JUSTIN D SCHILLING MI 3.0 1199
## 45 DEREK YAN MI 3.0 1242
## 46 JACOB ALEXANDER LAVALLEY MI 3.0 377
## 47 ERIC WRIGHT MI 2.5 1362
## 48 DANIEL KHAIN MI 2.5 1382
## 49 MICHAEL J MARTIN MI 2.5 1291
## 50 SHIVAM JHA MI 2.5 1056
## 51 TEJAS AYYAGARI MI 2.5 1011
## 52 ETHAN GUO MI 2.5 935
## 53 JOSE C YBARRA MI 2.0 1393
## 54 LARRY HODGE MI 2.0 1270
## 55 ALEX KONG MI 2.0 1186
## 56 MARISA RICCI MI 2.0 1153
## 57 MICHAEL LU MI 2.0 1092
## 58 VIRAJ MOHILE MI 2.0 917
## 59 SEAN M MC CORMICK MI 2.0 853
## 60 JULIA SHEN MI 1.5 967
## 61 JEZZEL FARKAS ON 1.5 955
## 62 ASHWIN BALAJI MI 1.0 1530
## 63 THOMAS JOSEPH HOSMER MI 1.0 1175
## 64 BEN LI MI 1.0 1163
## Avg Opponent Rating
## 1 1605.286
## 2 1469.286
## 3 1563.571
## 4 1573.571
## 5 1500.857
## 6 1518.714
## 7 1372.143
## 8 1468.429
## 9 1523.143
## 10 1554.143
## 11 1467.571
## 12 1506.167
## 13 1497.857
## 14 1515.000
## 15 1483.857
## 16 1385.800
## 17 1498.571
## 18 1480.000
## 19 1426.286
## 20 1410.857
## 21 1470.429
## 22 1300.333
## 23 1213.857
## 24 1357.000
## 25 1363.286
## 26 1506.857
## 27 1221.667
## 28 1522.143
## 29 1313.500
## 30 1144.143
## 31 1259.857
## 32 1378.714
## 33 1276.857
## 34 1375.286
## 35 1149.714
## 36 1388.167
## 37 1384.800
## 38 1539.167
## 39 1429.571
## 40 1390.571
## 41 1248.500
## 42 1149.857
## 43 1106.571
## 44 1327.000
## 45 1152.000
## 46 1357.714
## 47 1392.000
## 48 1355.800
## 49 1285.800
## 50 1296.000
## 51 1356.143
## 52 1494.571
## 53 1345.333
## 54 1206.167
## 55 1406.000
## 56 1414.400
## 57 1363.000
## 58 1391.000
## 59 1319.000
## 60 1330.200
## 61 1327.286
## 62 1186.000
## 63 1350.200
## 64 1263.000
write.csv(info_table, file = "ChessTable.csv", sep = ',', col.names = TRUE, row.names = FALSE)
## Warning in write.csv(info_table, file = "ChessTable.csv", sep = ",",
## col.names = TRUE, : attempt to set 'col.names' ignored
## Warning in write.csv(info_table, file = "ChessTable.csv", sep = ",",
## col.names = TRUE, : attempt to set 'sep' ignored