Re: [R] Find the 50 highest values in a matrix

From: Nikhil Kaza <nikhil.list_at_gmail.com>
Date: Fri, 18 Jun 2010 02:52:14 -0400

Matrix is just a vector. So order should work haven't verified the following code.

a <- matrix(rnorm(4000*2000), 4000, 2000) b <- order(a, na.last=TRUE, decreasing=TRUE)[1:50]

use %% or %/% to get the row# and column #s

Nikhil Kaza
Asst. Professor,
City and Regional Planning
University of North Carolina

nikhil.list_at_gmail.com

On Jun 18, 2010, at 1:41 AM, uschlecht wrote:

>
> Hi,
>
> I have a huge matrix (4000 * 2000 data points) and I would like to
> retrieve
> the coordinates (column and row) for the top 50 (or x) values. Some
> positions in the matrix have NA as a value. These should be discarded.
>
> My current method is to replace all NAs by 0, then rank all the
> values and
> then extract the positions with the 50 highest ranks. It is very
> time-consuming!
>
> Is there a simpler way to do this?
>
> Thank you,
> Ulrich
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Find-the-50-highest-values-in-a-matrix-tp2259721p2259721.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
b - b%%nrow(a)



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 18 Jun 2010 - 07:11:12 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 18 Jun 2010 - 07:40:33 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