Re: [R] Retrieving the 2 row of "dist" computations

2010-06-11 Thread Jeff08
Edit: I'm stupid and visualized the "dist" matrix incorrectly in my head. Should be Column # = x, Row # = y. n = 827-(x-2) index = y-1+(n+827)(827-n+1)/2 Everything works just fine. Thanks! Jeff08 wrote: > > Edit: > > There is something funky about the code. It definitely returns the right

Re: [R] Retrieving the 2 row of "dist" computations

2010-06-10 Thread Jeff08
Hey Jorge, Don't know if you received this but, essentially I found something weird with the outputs. Edit: There is something funky about the code. It definitely returns the right column of the "distance" data, but returns an incorrect row. Code: NCols=250 NRows=829 myMat<-matrix(runif(NCols

Re: [R] Retrieving the 2 row of "dist" computations

2010-06-10 Thread Jeff08
Edit: There is something funky about the code. It definitely returns the right column of the "distance" data, but returns an incorrect row. Code: NCols=250 NRows=829 myMat<-matrix(runif(NCols*NRows), ncol=NCols) d<-dist(myMat) e<-sort.list(d) e<-e[1:5] ##Retrieve minimum 5 distances k <-

Re: [R] Retrieving the 2 row of "dist" computations

2010-06-10 Thread Jeff08
Hey, The code definitely works, but I may need a more elegant way to do it. Rather than 5 rows, the full data contains 829 rows, so instead of d of length 10, d will be of length 343206. Jorge Ivan Velez wrote: > > Hi there, > > I am sure there is a better way to do it, but here is a suggest

Re: [R] Retrieving the 2 row of "dist" computations

2010-06-09 Thread Bill.Venables
m), arr.ind = TRUE)[1,] ij -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff08 Sent: Thursday, 10 June 2010 1:30 PM To: r-help@r-project.org Subject: [R] Retrieving the 2 row of "dist" computations Dear R Gur

Re: [R] Retrieving the 2 row of "dist" computations

2010-06-09 Thread Jorge Ivan Velez
Hi there, I am sure there is a better way to do it, but here is a suggestion: res <- matrix(NA, ncol = 2, nrow = 5) for(i in 1:5) res[i, ] <- which(as.matrix(d) == sort(d)[i], arr.ind = TRUE)[1,] res HTH, Jorge On Wed, Jun 9, 2010 at 11:30 PM, Jeff08 <> wrote: > > Dear R Gurus, > > As you pro

[R] Retrieving the 2 row of "dist" computations

2010-06-09 Thread Jeff08
Dear R Gurus, As you probably know, dist calculates the distance between every two rows of data. What I am interested in is the actual two rows that have the least distance between them, rather than the numerical value of the distance itself. For example, If the minimum distance in the following