student <- read.csv("NumberGameData.csv")
x_avg = mean(student$X) #total of all X
y_avg = mean(student$Y) #total of all Y
name_and_guess = vector(length = length(student$Name))
#stores the name and their euclidean distance from the mean
# formula: sqrt( (x_2 - x_1)^2 + (y_2 - y_1)^2 )
euclidean_dist <- function(list_a, list_b, avg_a, avg_b) {
guesses <- vector(length = length(list_a)) #creating a container to store the euclidean dist of the guesses
for (i in 1:length(list_a)) { #calculate the dist btw the guesses and the class average
dist <- sqrt( (avg_a - list_a[i])^2 + (avg_b - list_b[i])^2 )
guesses[i] = dist #adding each distance to a vector, then adding it to a data frame to match names
#print(guesses[i]) #uncomment for error checking
}
name_and_guess <- data.frame(Name = c(student$Name), Guess = c(guesses))
}
name_and_guess <- euclidean_dist(student$X,student$Y, x_avg, y_avg)
print("The closest guess was made by ")
## [1] "The closest guess was made by "
print(min(name_and_guess$Name))
## [1] "AJ Jansen"
#name_and_guess <- euclidean_dist(student$X,student$Y, x_avg, y_avg, student$Name, name_and_guess )