Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions Ex_08.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
## read in table with score data
scores = read.table("UWvMSU_1-22-13.txt", sep = "\t", header = T, stringsAsFactors = F)

## declare all variable to be used
wisconsin = 0
msu = 0

scoreUW = 0
scoreMSU = 0

## set up for loop to run through all rows of scores table
for (i in 1:nrow(scores)){
## if team column is UW then put the scores into a new vector
if(scores$team[i] == "UW"){
scoreUW [i] = wisconsin + scores$score[i]
wisconsin = scoreUW[i]
scoreMSU [i] = msu
} else{
scoreMSU [i] = msu + scores$score[i]
msu = scoreMSU[i]
scoreUW[i] = wisconsin
}
}
## plot the functions above
plot(scores$time, wisconsin,
main = "UW/MSU Scores vs Time",
ylab = "Scores",
xlab = "Time (min)",
type = "l",
col = "red")
grid(NULL,NULL)
lines(scores$time, msu, col="green")
legend("topleft",
c("UW", "MSU"),
fill = c("red","green"))


### Guessing Number Game ###

## generate random number that the user will try to guess what it is
magicNum = sample(1:100,1, replace = TRUE)

## tell the user about the guessing game
print("Welcome the Guessing Game. You will have 10 chances to guess the number (1-100) I am thinking of. Are you ready? Here we go.")

## set counter for guess attempts
counter = 1

## create while loop to end after 10 guess attempts have been made or correct answer
while (counter <= 10) {
## have user input guess
guess = readline(prompt ="Please enter your guess: ")
## set if else statements for when user guesses right, too high, or too low
if (guess == magicNum){
print("WOW WEE WOW WOO WOW! You got it right! Congrats!")
options("show.error.messages" = F)
stop()
} else if (guess < magicNum){
print(paste0("The number you guessed is lower than the magic number. You have ", 10-counter, " attempts left."))
counter = counter + 1
} else if (guess > magicNum) {
print(paste0("The number you guessed is higher than the magic number. You have ", 10-counter, " attempts left."))
counter = counter + 1
}
}
24 changes: 24 additions & 0 deletions Tut10.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
dt = data.frame(a = c(1:4),
b = c(5:8),
c = c(9:12))

for (i in 1:length(dt$a)){
row = dt[i,]
print(row)

col.3 = dt$c[i]
print(col.3)
}

wages = read.csv("wages.csv", stringsAsFactors = F, header = T)
maleWage = 0
femaleWage = 0
for (i in 1:length(wages$gender)){
if (wages$gender[i] == 'male'){
maleWage = maleWage + wages$wage[i]
} else {
femaleWage = femaleWage + wages$wage[i]
}
}
print(maleWage)
print(femaleWage)
151 changes: 0 additions & 151 deletions iris.csv

This file was deleted.