简体   繁体   English

计算3点的欧几里得距离

[英]Calculate the Euclidean distance of 3 points

I have a data.frame (Centroid) that contains points in virtual 3D space (columns = AV, V and A), each representing a character (column = Character). 我有一个data.frame(Centroid),它包含虚拟3D空间中的点(列= AV,V和A),每个点代表一个字符(列= Character)。 Each row contains a different character. 每行包含一个不同的字符。

AV<-c(37.9,10.87,40.05)
V<-c(1.07,1.14,1.9)
A<-c(0.04,-1.23,-1.1)
Character<-c("a","A","b")

centroid = data.frame(AV,V,A,Character)
centroid
     AV    V     A Character
1 37.90 1.07  0.04         a
2 10.87 1.14 -1.23         A
3 40.05 1.90 -1.10         b

I wish to know the similarity/dissimilarity between each character. 我想知道每个角色之间的相似/不同。 For example, "a" corresponds to 37.9, 1.07 and 0.04 whilst "A" corresponds to 10.87, 1.14, -1.23. 例如,“ a”对应于37.9、1.07和0.04,而“ A”对应于10.87、1.14,-1.23。 I want to know the distance between these characters/ 3 points. 我想知道这些字符/ 3点之间的距离。

I believe I can calculate this using Euclidean distance between each character, but am unsure of the code to run. 我相信我可以使用每个字符之间的欧几里得距离来计算此值,但是不确定代码是否可以运行。

I have attempted to use 我尝试使用

dist(as.matrix(Centroids))   

But have been unsuccessful, as this just gives a big print in the console. 但这并没有成功,因为这在控制台中只是一个很大的标志。 Any assistance would be greatly appreciated. 任何帮助将不胜感激。

Following may be helpful: 以下内容可能会有所帮助:

AV<-c(37.9,10.87,40.05)
V<-c(1.07,1.14,1.9)
A<-c(0.04,-1.23,-1.1)
centroid = data.frame(A,V,AV)
centroid
      A    V    AV
1  0.04 1.07 37.90
2 -1.23 1.14 10.87
3 -1.10 1.90 40.05

mm = as.matrix(centroid)
mm
         A    V    AV
[1,]  0.04 1.07 37.90
[2,] -1.23 1.14 10.87
[3,] -1.10 1.90 40.05

dist(mm)
          1         2
2 27.059909          
3  2.571186 29.190185

as.dist(mm)
       A     V
V  -1.23      
AV -1.10  1.90

It is not clear what you mean by "Character<-c(a,A,b)" 您不清楚“字符<-c(a,A,b)”是什么意思

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM