Question: Complete the R function distances_between. With two given data frames x,y of numeric data, having the same column names, return a matrix of m rows

Complete the R function "distances_between". With two given data frames x,y of numeric data, having the same column names, return a matrix of m rows and n columns (where nrow(x) = m and nrow(y) = n) where element m[i,j] gives the euclidean distance between the ith row of x and the jth row of y

# example: # if x = data.frame(a=1:2, b=2:3) # y = data.frame(a=1:3, b=2:4) # then the returned matrix should have 2 rows and 3 columns, and the value of the first row and third column should be the distance between the first row of x and the third row of y.

distances_between = function(x,y) { m = nrow(x) n = nrow(y) # YOUR CODE HERE (3) # HINT: rbind the two data frames together, get an # (m+n) by (m+n) distance matrix using R function 'dist', # and then get the rows and columns you need from the matrix }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!