Re: [R] extract cells by columns/rows from matrix

From: Jannis <bt_jannis_at_yahoo.de>
Date: Fri, 15 Apr 2011 15:38:27 +0200

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

gives you the indices of the largest element.

which(data==data[order(data)[2]],arr.ind=TRUE)

the indices of the second largest.

Best
Jannis

On 04/14/2011 10:23 PM, Nicolas Gutierrez wrote:
> hi All,
>
> I have a matrix Ufi (x by y)
>
> 1 2 3 4 5
> 1 0 0 0 0 3
> 2 0 0 0 9 0
> 3 0 2 0 0 3
> 4 0 0 1 0 0
> 5 0 1 0 0 0
>
> And I need the x and y "coordinates" of those cells with maximum values:
>
> First:
>
> x=4; y=2 (Value=9)
>
> Second:
>
> x=5; y=3 (value=3)
>
> Any help?
> THANKS!
>
> Nic
>
> ______________________________________________
> R-help_at_r-project.org 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.
>



R-help_at_r-project.org 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. Received on Fri 15 Apr 2011 - 13:44:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 15 Apr 2011 - 14:00:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive