[R] location of maximum

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Tue Mar 5 16:00:09 CET 2002


Patrick Buetzberger <patrick at giub.unibe.ch> writes:

> Dear R-users,
> 
> I'm trying to extract the exact location of the maximum value in a
> vector or a matrix, meaning I want not only the maximum itself but also
> at which position (e.g row 6, column 12) it is located.
> I appreciate any suggestions.

To find which element of x is equal to the maximum of x, try

which(x==max(x))

if you want the array index of the maximum of a matrix, use

which(m==max(m), arr.ind=TRUE)

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list