I have a dataframe with each row being a different site (51 sites), and each column being mean values of a different continuous environmental variable (19 variables).
I am trying to calculate a measure of environmental similarity/dissimilarity by using a distance calculation between sites.
I would like to calculate either a standardized Euclidean distance or Mahalanobis distance.
I have managed to get them to work with both the distance function in the package ecodist, and the dist.quant()
function in the package ade4 in [R].
E.g.
AusEnvDist <- distance(AusEnvNum, method="euclidean", sprange=NULL)
However my outputs are the same regardless of how the dataframe is organized (i.e., sites being in rows or columns) – I get an output matrix of $19\times19$ instead of $51\times51$ – i.e., it's not calculating the distance between sites, but between variables.
Any ideas on how to fix this?
Or a better method for getting a singular "environmental" value for each site?
Best Answer
I tried this and got different results (as expected) from the distances of a data frame and its transpose:
dist2
gives a single distance (betweenx1
andx2
).dist1
gives a $10\times10$ matrix (since I putupper = TRUE
anddiagonal = TRUE
)