Quantcast

Help: find the index of the minimum of entries

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Help: find the index of the minimum of entries

chee
Dear All,
I would like to ask a question on how to find the index of the minimum of entries of a numeric vector, without using loops or user defined functions.
Suppose we have a vector:
a <- c(3,1,2)
then,
min(a) = 1
and its index is 2.

Target:  how to get the index of this minimum? How to get the indices  if multiple entries assume this same minimum?

Thank you,
Chee
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Help: find the index of the minimum of entries

Henrique Dallazuanna
Try which.min(a)

On Wed, Aug 24, 2011 at 1:03 PM, Chee Chen <[hidden email]> wrote:

> Dear All,
> I would like to ask a question on how to find the index of the minimum of entries of a numeric vector, without using loops or user defined functions.
> Suppose we have a vector:
> a <- c(3,1,2)
> then,
> min(a) = 1
> and its index is 2.
>
> Target:  how to get the index of this minimum? How to get the indices  if multiple entries assume this same minimum?
>
> Thank you,
> Chee
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Help: find the index of the minimum of entries

Michael Weylandt
In reply to this post by chee
which.min()

more generally

which(a==min(a))

Michael Weylandt

On Wed, Aug 24, 2011 at 12:03 PM, Chee Chen <[hidden email]> wrote:

> Dear All,
> I would like to ask a question on how to find the index of the minimum of
> entries of a numeric vector, without using loops or user defined functions.
> Suppose we have a vector:
> a <- c(3,1,2)
> then,
> min(a) = 1
> and its index is 2.
>
> Target:  how to get the index of this minimum? How to get the indices  if
> multiple entries assume this same minimum?
>
> Thank you,
> Chee
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Loading...