diff --git a/Exercise_8-1.R b/Exercise_8-1.R new file mode 100644 index 0000000..9184e40 --- /dev/null +++ b/Exercise_8-1.R @@ -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") diff --git a/Exercise_8-2.R b/Exercise_8-2.R new file mode 100644 index 0000000..fbc4d27 --- /dev/null +++ b/Exercise_8-2.R @@ -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") + } +} diff --git a/Rplot of team scores.png b/Rplot of team scores.png new file mode 100644 index 0000000..eab41ca Binary files /dev/null and b/Rplot of team scores.png differ