Re: [R] Find the index for min of a matrix

From: <Bill.Venables_at_csiro.au>
Date: Mon, 31 Mar 2008 13:58:06 +1000

> W <- matrix(c(2,4,2,8,1,3), ncol = 3)
> which(W == min(W), arr.ind = TRUE) #### note difference...

     row col
[1,] 1 3

> W # chech

     [,1] [,2] [,3]
[1,] 2 2 1
[2,] 4 8 3

Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA

Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary):  +61 7 3826 7304
Mobile:                         +61 4 8819 4402
Home Phone:                     +61 7 3286 7700
mailto:Bill.Venables_at_csiro.au
http://www.cmis.csiro.au/bill.venables/

-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On Behalf Of kate
Sent: Monday, 31 March 2008 1:53 PM
To: r-help_at_r-project.org
Subject: [R] Find the index for min of a matrix

Hi,

My example is as the following,

W<-matrix(c(2,4,2,8,1,3),ncol=3)
which(W==min(W))

I would like to find the index for min of the matrix W, i.e. (1, 3) instead of 5 as the output. What command could I use?

Thanks,

Kate

        [[alternative HTML version deleted]]



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 Mon 31 Mar 2008 - 04:00:15 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 Mon 31 Mar 2008 - 04:30:27 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