Transformation and distances in R