I have two huge matrices with equal dimensions. I want to calculate Euclidean distance between them. I know this is the function:
euclidean_distance <- function(p,q){
sqrt(sum((p - q)^2))
}
and if these are two matrices:
set.seed(123)
mat1 <- data.frame(x=sample(1:10000,3),
y=sample(1:10000,3),
z=sample(1:10000,3))
mat2 <- data.frame(x=sample(1:100,3),
y=sample(1:100,3),
z=sample(1:1000,3))
then I need the answer be a new matrix 3*3 showing Euclidean distance between each pair of values of mat1 and mat2.
any suggestion please?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…