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
68 changes: 68 additions & 0 deletions Exercise08.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
### Problem 1 ###

setwd("C:/Users/Julian Najera/OneDrive - Johns Hopkins/Documents/Notre Dame/Semester 1/Introduction to Biocomputing/Biocomp_tutorial10/")

game <- read.table("UWvMSU_1-22-13.txt",header = TRUE,sep = "",stringsAsFactors = FALSE)

## Extract Points Scored for Individual School ##

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

## Calculate Cumulative Points Scored for Each School ##

cum_score_UW <-numeric(length(UW$score))
for(i in 1:length(UW$score)){
cum_score_UW[i]<-sum(UW$score[1:i])
}
cum_score_UW

cum_score_MSU <-numeric(length(MSU$score))
for(i in 1:length(MSU$score)){
cum_score_MSU[i]<-sum(MSU$score[1:i])
}
cum_score_MSU

# Alternative Approach Using Built-In Cumulative Function

# cum_score_UW <- cumsum(UW$score)
# cum_score_UW

# cum_score_MSU <- cumsum(MSU$score)
# cum_score_MSU

## Plot Scores ##

x1 <- UW$time
x2 <- MSU$time
y1 <- cum_score_UW
y2 <- cum_score_MSU


plot(x1,y1,type="l",main="UW vs. MSU Basketball Score", xlab = "Time (min)", ylab = "Points Scored")
lines(x2,y2)


### Problem 2 ###

## Generate a random number between 1 and 100 ##

guess_my_number <- function(number) {

for (i in 1:10){
my.guess <- strtoi(readline(prompt = "Guess a Number Between 1-100: "), base=0L)
if (my.guess > number){
print("Lower")
} else if (my.guess < number){
print("Higher")
} else {
print("Correct!")
break
}
}
}

## Test ##

number <- sample(100,1)