From 1f592660bce914becdd6b8ab889580ae53128eea Mon Sep 17 00:00:00 2001 From: Emily Chen Date: Wed, 10 Nov 2021 22:58:44 -0500 Subject: [PATCH 1/3] Exercise 08 --- Exercise 08 Submission.R | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Exercise 08 Submission.R diff --git a/Exercise 08 Submission.R b/Exercise 08 Submission.R new file mode 100644 index 0000000..c4377b6 --- /dev/null +++ b/Exercise 08 Submission.R @@ -0,0 +1,20 @@ +# Problem 1: Generate a graph using score-by-score info from game in txt file + +# Load the score-by-score information +UWvMSU<-read.table(file="UWvMSU_1-22-13.txt",header=TRUE,stringsAsFactors=FALSE) +# Organize score info by school +UW<-UWvMSU[UWvMSU$team=='UW',] +MSU<-UWvMSU[UWvMSU$team=='MSU',] +# Aggregate the score data for each school by the time +totalscoreUW<-numeric(length(UW$score)) +for(i in 1:length(UW$score)){ + totalscoreUW[i]<-sum(UW$score[1:i]) +} + +totalscoreMSU<-numeric(length(MSU$score)) +for(i in 1:length(MSU$score)){ + totalscoreMSU[i]<-sum(MSU$score[1:i]) +} + +# Plot aggregate scores with time as the other variable +time<-UWvMSU[UWvMSU$time=='time'] From 23fe87f0adf6e75d983016629bd88b9c80890155 Mon Sep 17 00:00:00 2001 From: Emily Chen Date: Wed, 10 Nov 2021 23:58:58 -0500 Subject: [PATCH 2/3] This is my submission for Exercise 08 --- Exercise 08 Submission.R | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Exercise 08 Submission.R b/Exercise 08 Submission.R index c4377b6..8821524 100644 --- a/Exercise 08 Submission.R +++ b/Exercise 08 Submission.R @@ -1,4 +1,4 @@ -# Problem 1: Generate a graph using score-by-score info from game in txt file +## Problem 1: Generate a graph using score-by-score info from game in txt file # Load the score-by-score information UWvMSU<-read.table(file="UWvMSU_1-22-13.txt",header=TRUE,stringsAsFactors=FALSE) @@ -17,4 +17,28 @@ for(i in 1:length(MSU$score)){ } # Plot aggregate scores with time as the other variable -time<-UWvMSU[UWvMSU$time=='time'] +x1<-UW$time +x2<-MSU$time +y1<-totalscoreUW +y2<-totalscoreMSU +plot(x1,y1,type='l',xlab='time',ylab='score') +lines(x2,y2) + + +## Problem 2:Generate "Guess my number" game + +# Generate random number from 1-100 +randomnum<-sample(1:100,1) +# Limit to 10 guesses +for (i in 1:10){ + guess<-readline(prompt="Pick a number from 1 to 100")} +# Generate output "lower", "higher", and "correct" +if(randomnumguess){ + print("higher") + }else{ + if(randomnum==guess){ + print("correct!") + } +} \ No newline at end of file From 1c58a9844dfd730ad5094afc30c2411f0756c212 Mon Sep 17 00:00:00 2001 From: Emily Chen Date: Thu, 11 Nov 2021 09:59:33 -0500 Subject: [PATCH 3/3] This is my submission for Exercise 08 --- Exercise 08 Submission.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Exercise 08 Submission.R b/Exercise 08 Submission.R index 8821524..d0c70d9 100644 --- a/Exercise 08 Submission.R +++ b/Exercise 08 Submission.R @@ -31,13 +31,13 @@ lines(x2,y2) randomnum<-sample(1:100,1) # Limit to 10 guesses for (i in 1:10){ - guess<-readline(prompt="Pick a number from 1 to 100")} + guess<-readline(prompt="Pick a number from 1 to 100") # Generate output "lower", "higher", and "correct" if(randomnumguess){ print("higher") - }else{ + }else if(randomnum==guess){ print("correct!") }