look at the `arr.ind' argument of ?which(), e.g.,
x <- matrix(rnorm(9), 3, 3)
x
which(x == max(x), arr.ind = TRUE)
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "mirko sanpietrucci" <mirko.sanpietrucci at email.it>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, June 01, 2007 11:09 AM
Subject: [R] how to extract the maximum from a matrix?
> Dear UseRs,
> I have a very simple question. I have a big matrix (say x) including
> probabilities (values in (0,1)).
> I have to store in a list the names of the row and the column where
> max(x)
> is located. How can I proceed?
>
> Thanks in advance for your assistance!
>
> mirko
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm