Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Exercise10NK.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Nathan Kroeze
# 12/2/2022
# Exercise 10

library(tidyverse)

### Cumulative Scores

setwd("C:/Users/Natha/Desktop/Biocomputing/Exercise10")
game <- read.table("UWvMSU_1-22-13.txt",sep = "", header = TRUE)

MSU <- game[game$team=="MSU",]
UW <- game[game$team=="UW",]

MSU_score <- MSU$score
UW_score <- UW$score

sum_MSU <- vector("numeric",length(MSU_score))
sum_UW <- vector("numeric",length(UW_score))


for(i in 1:length(MSU_score)){
sum_MSU[i] <- sum(MSU_score[1:i])
}
for(i in 1:length(UW_score)){
sum_UW[i] <- sum(UW_score[1:i])
}

MSU$cum_score <- sum_MSU
UW$cum_score <- sum_UW
game2 <- rbind(MSU,UW)

ggplot(game2, aes(x = time, y = cum_score, group = team)) +
geom_line(aes(color = team),linewidth = 1.5) + ylab("Cumulative Score")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an alternative approach:

load table of scoring

scoring=read.table("UWvMSU_1-22-13.txt",header=TRUE,sep="\t",stringsAsFactors=FALSE)

look at data

dim(scoring)
head(scoring)

preallocating matrix to store cumulative scores

cum_scores=matrix(NA,nrow(scoring)+1,3)
cum_scores[,1]=c(0,scoring[,1])
cum_scores[1,2:3]=0
colnames(cum_scores)=c("time","UW","MSU")

looping through individual scoring events

for(i in 1:nrow(scoring)){
if(scoring[i,2]=="UW"){
cum_scores[(i+1),2]=cum_scores[i,2]+scoring[i,3]
cum_scores[(i+1),3]=cum_scores[i,3]
}else{
cum_scores[(i+1),2]=cum_scores[i,2]
cum_scores[(i+1),3]=cum_scores[i,3]+scoring[i,3]
}
}



### Number Game

number = sample(1:100,1)
count = 0

for(i in 1:10){
input <- readline("Guess: ")
if(input == number){
print("Correct!")
break
}else if(input < number){
print("Higher...")
}else{print("Lower...")}
count <- count + 1
if(count == 10){
print("Better luck next time!")
count <- 0
}
}