<- function(x,y) {
mean_distance <- (x-y)^2
distance mean(distance)
}
mean_distance(c(10,3,5), c(0.1,3,0))
[1] 41.00333
As we talked about in class, one common way to measure the distance between two numbers \(a\) and \(b\) is to compute
\[ distance = (a-b)^2 \]
For this code challenge, you need to write a function that
Takes in two vectors of numbers (the vectors will have the same number of elements in them)
Computes the distance between corresponding elements in each vector (i.e., the distance between the first element in the the first vector and the first element in the second vector, etc.)
Returns the average distance between corresponding elements in each vector.
Use your function to compute the distance between c(10,3,5)
and c(0.1,3,0)
Rules:
To win
You must email me the answer and your function brantly.callaway@uga.edu
I’ll call the function on two vectors of numbers. If it computes the correct average distance between two vectors, then you win.
Solution below…
<- function(x,y) {
mean_distance <- (x-y)^2
distance mean(distance)
}
mean_distance(c(10,3,5), c(0.1,3,0))
[1] 41.00333