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.
Solution below…
mean_distance <- function(a,b) {
distance <- (a-b)^2
mean(distance)
}
mean_distance(c(10,3,5), c(0.1,3,0))
## [1] 41.00333