I am trying to find the Mahalanobis Distance between the different species in the iris
dataset in R. I was able to find the distance between setosa
and versicolor
by the following code:
library(HDMD)
#To get Mahalanobis distances between Setosa and Versicolor,
set.vers<-pairwise.mahalanobis(x=iris[1:100,1:4], grouping=iris[1:100,]$Species)
md= sqrt(set.vers$distance)
However, I am struggling to do the same for setosa
and virginica
. I am not sure how to select the first 50 rows and last 50 rows of the data set (i.e. not have any versicolor
data)
Here is a way to get all combinations of levels in
iris$Species
withcombn
and compute the Mahalanobis distances.