[R] locating element in distance matrix

David Winsemius dwinsemius at comcast.net
Fri Jan 11 19:36:30 CET 2013


On Jan 11, 2013, at 9:55 AM, eliza botto wrote:

>
> Dear useRs,
> I have a very basic question. I have a distance matrix and i skipped  
> the upper part of it deliberately.

I have no idea what htat means. Code is always helpful in resolving  
ambiguities.

> The distance matrix is 1000*1000.  Then i used "min" command to  
> extract the lowest value from that matrix. Now i want to know what  
> is the location of that lowest element? More precisely, the row and  
> column number of that lowest element.
> Thanks in advance

?which
which( distmat == min(distmat), arr.ind=TRUE)

(It's possible to have more than one match and it would  be up to you  
to decide how to break ties.)

-- 

David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list