Skip to content

Lowest k values of list

6 messages · Markus Mühlbacher, Jorge Ivan Velez, David Winsemius +2 more

#
Hi @ all,

how do I get the largest or lowest k values of list? It must similar to the min() / max() function, but I just don't get it. 

Best wishes,
Markus
#
On Sep 5, 2008, at 11:26 AM, Markus M?hlbacher wrote:

            
Might depend on how you define "high" and "low". Consider these  
experiments:

 > z <- list(1,4,"5",6,,2,3)
 > head(sort(unlist(z)),n=2)
[1] "1" "2"
 > tail(sort(unlist(z)),n=2)
[1] "5" "6"


 > z <- list(1,2,3,4,"5",6,"a")
 > tail(sort(unlist(z)),n=2)
[1] "6" "a"
 > head(sort(unlist(z)),n=2)
[1] "1" "2"
#
Do you mean a vector? If so, head/tail will work for you:
[1] 0.26550866 0.37212390 0.57285336 0.90820779 0.20168193 0.89838968
0.94467527
 [8] 0.66079779 0.62911404 0.06178627
[1] 0.06178627 0.20168193 0.26550866 0.37212390 0.57285336
[1] 0.6291140 0.6607978 0.8983897 0.9082078 0.9446753

        
On Fri, Sep 5, 2008 at 11:26 AM, Markus M?hlbacher <muehliman at yahoo.com> wrote:

  
    
#
In addition to the other responses, you may want to look at the 'partial' argument to sort.  For large vectors it may speed things up to not sort everything if all you care about is the top and bottom few.

Try:
Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
(801) 408-8111