diff --git a/GuessMyNumberGame.Rscript.R b/GuessMyNumberGame.Rscript.R new file mode 100644 index 0000000..522c696 --- /dev/null +++ b/GuessMyNumberGame.Rscript.R @@ -0,0 +1,27 @@ +##Guess My Number + +###A game that allows user to guess a randomly generated number and gives feedback +###for correct and incorrect guesses. + +#Generate a random number between 1 and 100 + +range <- 1:100 +randonumber <- sample(range, i) + +# Write a for loop that allows a user to guess up to ten times +# Output 'Lower' if guess is greater than random number +# Output 'Higher' if guess is less than random number +# Output 'Correct!' if user guesses random number + +for (i in 1:10) { + guess <- readline(prompt = "Guess:") + guess <- as.integer(guess) + if (guess > randonumber){ + print("Lower") + } else if (guess < randonumber){ + print("Higher") + } else { + print("Correct!") + break + } + } \ No newline at end of file diff --git a/UWvMSU_Summary.Rscript b/UWvMSU_Summary.Rscript new file mode 100644 index 0000000..9b5dd3c --- /dev/null +++ b/UWvMSU_Summary.Rscript @@ -0,0 +1,26 @@ +#Parse score data for each team +data <- read.table("UWvMSU_1-22-13.txt",header = TRUE, stringsAsFactors = FALSE) +UWscores <- data[data$team=="UW",] +MSUscores <- data[data$team=="MSU",] + +#Create cummulative totals for each team +UWtotal <- numeric(length(UWscores$score)) +for(row in 1:length(UWscores$score)){ + UWtotal[row] <- sum(UWscores$score[1:row]) +} + +MSUtotal <- numeric(length(MSUscores$score)) +for(row in 1:length(MSUscores$score)){ + MSUtotal[row] <- sum(MSUscores$score[1:row]) +} + +# Assign cummulative scores and totals to coordinates and plot on one graph +x1 <- UWscores$time +y1 <- UWtotal +x2 <- MSUscores$time +y2 <- MSUtotal +plot(x1,y1,type = "l", pch=19, main = "UW vs. MSU Basketball + 1-22-13", col="red", xlab = "Time (min)", ylab = "Score") +lines(x2,y2, pch=18, col="blue", type = "l", lty=2) +legend(25, 15, legend=c("UW", "MSU"), col=c("red","blue"), lty = 1:2, cex = 0.8) +