HI, May be this helps: set.seed(18) A<-matrix(sample(1:4000,15*365,replace=TRUE),ncol=15) set.seed(25) B<-sample(1:800,1*365,replace=TRUE) res<-do.call(rbind,lapply(split(A,col(A)),function(x) dist(rbind(x,B)))) head(res) # [,1] #1 37812.43 #2 38258.21 #3 39025.13 #4 37572.35 #5 37885.32 #6 38053.42 A.K.
----- Original Message ----- From: eliza botto <eliza_bo...@hotmail.com> To: "r-help@r-project.org" <r-help@r-project.org> Cc: Sent: Saturday, November 17, 2012 9:07 PM Subject: [R] euclidean dist. between matrices Dear Users,I have two matrices A=15*365 and B=1*365. i want to calculate "Euclidean Distance" between these matrices in such a way that i should have euclidean distance of matrix B against all the columns of matrix A. More precisely, first i want euclidean dist. of column 1 of A against B, then column 2 against B, 3rd column of A against B and so on.is there a way in r to do it?your help is deeply appreciated.. eliza [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.