Skip to content
Open
Show file tree
Hide file tree
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
35 changes: 35 additions & 0 deletions Exercise_8-1.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#1. create summary plot from UWvMSU_1-22-13.txt

#setting it to my computer
setwd("/Users/erinlewis/Desktop/Biocomp_tutorial10/")

#separate both teams points
game <- read.table("UWvMSU_1-22-13.txt", header = TRUE, sep = "\t")

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

#create two data frames to store each team's output
UWscores <- data.frame('time' = UW_game$time,
'score' = numeric(length(UW_game$score)))

MSUscores <- data.frame('time' = MSU_game$time,
'score' = numeric(length(MSU_game$score)))

#create for loops in order to get the cumulative score for the two teams
sumUW = 0
sumMSU = 0

for(i in 1:length(UW_game$team)){
sumUW = sumUW + game$score[i]
UWscores$score[i] <- sumUW
}

for(i in 1:length(MSU_game$team)){
sumMSU = sumMSU + game$score[i]
MSUscores$score[i] <- sumMSU
}

#creating the plot
plot(UWscores$time, UWscores$score, type = 'l', xlab="Time (min)", ylab="Score", col="red")
lines(MSUscores$time,MSUscores$score, col="green")
26 changes: 26 additions & 0 deletions Exercise_8-2.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#2. Write a game where you guess a number randomly generated by the computer

#generate random number
num <- sample(1:100,1)

#create placeholder vector to store user input
guess <- -1

#prompt user input
cat("I'm thinking of a number 1-100...")

#for loop to determine what output to give based on user input
#for loop will run 10 times or it will stop when correct answer input due to break
for(i in 1:10){
guess <- as.integer(x = readline(prompt="Enter an integer: "))
if (guess == num){
cat("Correct!")
break
}
else if (guess < num){
cat("Higher")
}
else if(guess > num){
cat("Lower")
}
}
Binary file added Rplot of team scores.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.