From a8e39541bd1d70f9c1a4e7c68de5661f2dc001a0 Mon Sep 17 00:00:00 2001 From: Elias Date: Fri, 2 Dec 2022 10:40:58 -0500 Subject: [PATCH 1/2] Elias Issa Exercise 10 --- Exercise10.R | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Exercise10.R diff --git a/Exercise10.R b/Exercise10.R new file mode 100644 index 0000000..f7ea5f9 --- /dev/null +++ b/Exercise10.R @@ -0,0 +1,58 @@ +#Elias Issa Exercise10 + +#Set Working Directory +setwd("/Users/elias/Downloads/Exercise10-main") +#Initialize ggplot2 +library(ggplot2) +#Question 1 +#import data +data <- read.table("UWvMSU_1-22-13.txt", header= T, sep = "\t", stringsAsFactors=FALSE) +#subset of MSU score +MSU<-subset(data,team == "MSU") +#subset of MSU cumulative score +MSU_cum<-subset(data,team == "MSU") +#subset of UW +UW<-subset(data,team == "UW") +#subset of UW cumulative score +UW_cum<-subset(data,team == "UW") +#adds the previous cumulative score to the point total of the next score for UW +for(i in 2:nrow(UW)){ + UW_cum$score[i] <-UW_cum$score[i-1]+UW$score[i] + print(UW_cum$score[i]) +} + +#adds the previous cumulative score to the point total of the next score for MSU + +for(i in 2:nrow(MSU)){ + MSU_cum$score[i] <-MSU_cum$score[i-1]+MSU$score[i] + print(MSU_cum$score[i]) +} + +#Plot of both cumulative data vs time with different colors +ggplot() + geom_line(data= MSU_cum, aes(x=time, y= score,color="red")) + geom_line(data= UW_cum, aes(x=time, y= score,color="black")) +theme_classic() + + #Question 2 +#uses a function to make the game easily replayable by putting it in a single function +guessmynumber<- function(){ + +#generates a random target +target <- sample(1:100,1) + +#tells player the game +print("I'm thinking of a number 1-100...") +for (i in 1:10){ + #loops through function 10 times to limit guesses to 10 + guess<-readline(prompt <-"Guess:") + guess<-as.integer(guess) + if(guess>target){ + print("Lower") + }else if(guess Date: Fri, 2 Dec 2022 10:48:14 -0500 Subject: [PATCH 2/2] Removed testing features --- Exercise10.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Exercise10.R b/Exercise10.R index f7ea5f9..f55f7db 100644 --- a/Exercise10.R +++ b/Exercise10.R @@ -1,7 +1,7 @@ #Elias Issa Exercise10 #Set Working Directory -setwd("/Users/elias/Downloads/Exercise10-main") +setwd("/Users/elias/Downloads/Exercise10") #Initialize ggplot2 library(ggplot2) #Question 1 @@ -18,14 +18,12 @@ UW_cum<-subset(data,team == "UW") #adds the previous cumulative score to the point total of the next score for UW for(i in 2:nrow(UW)){ UW_cum$score[i] <-UW_cum$score[i-1]+UW$score[i] - print(UW_cum$score[i]) } #adds the previous cumulative score to the point total of the next score for MSU for(i in 2:nrow(MSU)){ MSU_cum$score[i] <-MSU_cum$score[i-1]+MSU$score[i] - print(MSU_cum$score[i]) } #Plot of both cumulative data vs time with different colors