[R] locating minimum value in matrix

ISMA11 sma3il11 at gmail.com
Thu Oct 20 13:32:50 CEST 2011


Hi,

I was looking for a solution to the same problem. I just found something and
thought it might be useful to share.

Suppose you look for the positions of the minimum value in matrix D. Using a
little euclide division solves the problem easily. Here is my code.

min(D)
Dv=as.vector(D)
pos=which.min(Dv)
j0=floor(pos/nrow(D))+1
i0=pos%%nrow(D)
D[i0,j0] # must equal min(D)

Hope this is useful.

I.

--
View this message in context: http://r.789695.n4.nabble.com/locating-minimum-value-in-matrix-tp850619p3921598.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list