diff --git a/Exercise8Script.R b/Exercise8Script.R new file mode 100644 index 0000000..b47e70f --- /dev/null +++ b/Exercise8Script.R @@ -0,0 +1,55 @@ +###Marlee Shaffer +##Exercise 8 + +###Part 1 +##Generate a plot similar using the data summarized in UWvMSU to show cumulative score throughout the game for University of Wisconsin vs Michigan State University +#Load the data and make it a data frame +data<-read.table("UWvMSU_1-22-13.txt", header = TRUE, sep = "\t") +df<-as.data.frame(data) +#Data frame headers: time, team, score. All data mixed together +#Pull out data for UW and MSU separately +UWscore <-df[df$team == "UW",] +MSUscore <-df[df$team == "MSU",] +#Vectors for UW +UWtime<-UWscore$time +UWcscore<-cumsum(UWscore$score) +#Vectors for MSU +MSUtime<-MSUscore$time +MSUcscore<-cumsum(MSUscore$score) + +UWdf<-data.frame(UWtime, UWcscore) +MSUdf<-data.frame(MSUtime, MSUcscore) + +#Make plot +plot(UWdf, type = "l", col = "red", main = "Cumulative Score for UW vs MSU Basketball Game", xlab = "Time", ylab = "Cumulative Score") +lines(MSUdf, type = "l", col = "green") +legend("topleft", legend=c("UW", "MSU"), col=c("red", "green"), lty = 1, lwd = 2, title = "Team", box.lty=0, cex = 0.75) + +####Part 2 +###Guess my number + +rand<- sample(1:100, 1) + +for (i in 1:10){ + print("I'm thinking of a number 1 to 100.", quote=FALSE) + usernum <- as.integer(readline(prompt = "What is your guess? ")) + if (i < 10){ + if (usernum > rand) { + print("Lower", quote=FALSE) + } else if (usernum < rand){ + print("Higher", quote=FALSE) + } else { + print("Correct", quote=FALSE) + break + } + } + else { + if (usernum == rand){ + print("Correct", quote=FALSE) + } + else { + print("Sorry. Thanks for playing.", quote=FALSE) + } + } +} +