Mahalanobis distance of each pair of observations
I am trying to compute the Mahalanobis distance between each observations of a dataset dat , where each row is an observation and each column is a variable. Such distance is defined as: I wrote a function that does it, but I feel like it is slow. Is there any better way to compute this in R ? To generate some data to test the function: generateData <- function(nObs, nVar){ library(MASS) mvrnorm(n=nObs, rep(0,nVar), diag(nVar)) } This is the function I have written so far. They both work and for my data (800 obs and 90 variables), it takes approximatively 30 and 33 seconds for the method =