Hello,

I'm looking to get the values, row names and column names of the largest and
smallest values in a matrix.

Example (except is does not include the names):

> x <- swiss$Education[1:25]
> dat = matrix(x,5,5)
> colnames(dat) = c('a','b','c','d','c')
> rownames(dat) = c('z','y','x','w','v')
> dat
   a  b  c  d  c
z 12  7  6  2 10
y  9  7 12  8  3
x  5  8  7 28 12
w  7  7 12 20  6
v 15 13  5  9  1

> #top 10
> sort(dat,partial=n-9:n)[(n-9):n]
 [1]  9 10 12 12 12 12 13 15 20 28
> # bottom 10
> sort(dat,partial=1:10)[1:10]
 [1] 1 2 3 5 5 6 6 7 7 7

...except I need the rownames and colnames to go along for the ride with the
values...because of this, I am guessing the return value will need to be a
list since all of the values have different row and col names (which is
fine).

Regards,

Ben

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to