Skip to content
Back to formatted view

Raw Message

Message-ID: <da79af330803310723v3f046896r67f6fef5aae829ca@mail.gmail.com>
Date: 2008-03-31T14:23:18Z
From: Henrique Dallazuanna
Subject: Retrieving locations of element of a vector or matrix
In-Reply-To: <462917.64047.qm@web63907.mail.re1.yahoo.com>

I think that you can use:

x <- sample(1:20, 10)
head(sort(x), 5) #First 5 minimum values
head(sort(x, decreasing = TRUE), 5) #First 5 maximum values

On 31/03/2008, Yemi Oyeyemi <gmoyeyemi at yahoo.com> wrote:
> Hello all,
>   I have a problem of getting the locations of elements in a vector or matrix. I know one can use the command "which.min" or which.max" to get the location of minimum or maximum values in a vector. But is there any command to get the first k minimum values or maximum values in a vector.
>   Thanks
>
>
>  ---------------------------------
>  You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.
>         [[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.
>


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