Try this:

m <- rbind(c(4,5,2), c(2,8,9), c(5,2,3))
cbind(1:NROW(m), apply(m, 1, which.min))


On Thu, Sep 10, 2009 at 3:34 PM, annie Zhang <annie.zhang2...@gmail.com>wrote:

> Hi, All,
>
> How can I get the indices of the minimum elements in a matrix without using
> a loop?
>
> For example, if the matrix is
>
> 4 5 2
> 2 8 9
> 5 2 3
>
> Then I want to output (1,3), (2,1), (3,2).
>
> Thanks,
>
> Annie
>
>        [[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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[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