I have two datasets: 1) a [1 x m] matrix of "Ideal" conditions for m factors, and 2) a [n x m] matrix of n observations (rows) for each of the m factors. I would like to calculate, for each observation in the second matrix, how far it is from the "Ideal" condition. So the output would be n values that represent "distances" from ideal conditions. First question, is the Mahalanobis distance appropriate to use here? The m factors are spatial in nature, and are related to each other. Second question, how do I set this up in R? I have tried a few examples with mahalanobis(), mahalanobis.dist(), and pairwise.mahalnobis(), but I cannot see how these can be used with my example. When I've tried to use my matrices with these functions, I get an error: Error in solve.default(cov, ...) : Lapack routine dgesv: system is exactly singular: U[8,8] = 0 Which I have come to understand means that one of my matrices is singular and therefore cannot be inverted. I am not entirely sure how to get around this issue, or if it needs to be gotten around at all for my purposes. I have also read [this thread](http://stats.stackexchange.com/questions/65705/pairwise-mahalanobis-distance), but it's a bit over my head. The overall goal of this is to use the results to map out "Ideal" habitat ranges for a particular species. Any help, thoughts, or suggestions would be greatly appreciated!