[R] Euclidean distance function

2012-08-24 Thread Arbuckle
Hi, I should preface this problem with a statement that although I am sure this is a really easy function to write, I have tried and failed to get my head around writing functions in R. I can use R where functions exist to do what I want done, but have found myself completely incapable of writing

Re: [R] Euclidean distance function

2012-08-24 Thread Jean V Adams
Kev, The dist() function handles more than 2 dimensions. Using the example you provided ... mydat - structure(list(Species = c(spA, spB, spC, spD), x = c(2.9, 5.5, 1.4, 8.3), y = c(34.2, 46.5, 48.6, 56.1), z = c(0.54, 0.45, 0.84, 0.48), n = c(15.7, 19.4, 24.8,

Re: [R] Euclidean distance function

2012-08-24 Thread Arbuckle
Thank you kindly for both of the replies I've received, that does indeed work perfectly. I had been looking at the description of that function and it reads as though it only deals with 2-dimensional data. Thanks again! Kev -- View this message in context:

Re: [R] Euclidean distance function

2012-08-24 Thread Rui Barradas
Hello, You don't need to write a function. Try the following. nms - paste0(species, 1:4) mat - matrix(rnorm(16), ncol=4, dimnames = list(nms, nms)) ?dist dist(mat) dist(mat, diag = TRUE, upper = TRUE) Hope this helps, Rui Barradas Em 24-08-2012 11:56, Arbuckle escreveu: Hi, I should