Quantcast

how to extract the maximum from a matrix?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

how to extract the maximum from a matrix?

mirko sanpietrucci
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

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: how to extract the maximum from a matrix?

Dimitris Rizopoulos
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" <[hidden email]>
To: <[hidden email]>
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
>
> ______________________________________________
> [hidden email] 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

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Odp: how to extract the maximum from a matrix?

PIKAL Petr
In reply to this post by mirko sanpietrucci
Hi

If you have tried to go through help pages of max you could find out which
function, which can tell you position of your maximum.

which(x==max(x), arr.ind=T)

Regards

Petr Pikal
[hidden email]

[hidden email] napsal dne 01.06.2007 11:09:09:

> 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
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Loading...