[R] Find the index for min of a matrix
Bill.Venables at csiro.au
Bill.Venables at csiro.au
Mon Mar 31 05:58:06 CEST 2008
> 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.
More information about the R-help
mailing list