On Fri, Jan 11, 2013 at 11:55 AM, eliza botto <[email protected]>wrote:

>
> Dear useRs,
> I have a very basic question. I have a distance matrix and i skipped the
> upper part of it deliberately. 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
> elisa
>

You didn't provide sample data, but perhaps this will work for you.

> x <- matrix(sample(1:100000000, 1000000), 1000, 1000)
> min(x)
[1] 135
> row <- which(apply(x, 1, min) == min(x))
> col <- which(apply(x, 2, min) == min(x))
> x[row, col]
[1] 135

row and col are obviously the location in the matrix of the min.

HTH


James

        [[alternative HTML version deleted]]

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to