Re: [R] index of min elements in matrix

2009-09-10 Thread annie Zhang
Thanks for all your help. Yes, it's very helpful. Annie On Thu, Sep 10, 2009 at 11:42 AM, Marc Schwartz wrote: > On Sep 10, 2009, at 1:34 PM, annie Zhang wrote: > > Hi, All, >> >> How can I get the indices of the minimum elements in a matrix without >> using >> a loop? >> >> For example, if the

Re: [R] index of min elements in matrix

2009-09-10 Thread Marc Schwartz
On Sep 10, 2009, at 1:34 PM, annie Zhang 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 mat <- matrix(c(4, 2, 5, 5, 8, 2, 2, 9

Re: [R] index of min elements in matrix

2009-09-10 Thread Henrique Dallazuanna
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 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

[R] index of min elements in matrix

2009-09-10 Thread annie Zhang
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