an be extracted from a given body of data.
> ~ John Tukey
>
> -Oorspronkelijk bericht-
> Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> Namens andrew
> Verzonden: vrijdag 4 september 2009 4:24
> Aan: r-help@r-project.org
> Onderwerp: Re: [R
-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens
andrew
Verzonden: vrijdag 4 september 2009 4:24
Aan: r-help@r-project.org
Onderwerp: Re: [R] Easy way to get top 2 items from vector
it is speedier to use sort than a combinatio
it is speedier to use sort than a combination of [] and order:
N<- 100
x <- runif(N)
> system.time(x[order(x)[c(N-1,N)]])
user system elapsed
1.030.001.03
> system.time(sort(x)[c(N-1,N)])
user system elapsed
0.280.000.28
On Sep 4, 11:17 am, Noah Silverman wrot
Phil,
That's perfect. (For my application, I've never seen a tie. While
possible, the likelihood is almost none.)
Thanks!
--
Noah
On 9/3/09 4:29 PM, Phil Spector wrote:
> Noah -
>max(x[-which.max(x)] will give you the second largest value,
> but it doesn't handle ties.
>x[order(x,de
Hi Noah,
Next time try, please, send a short reproducible code/example.
May be this can be (not so elegant but) helpfull
myDF<-data.frame(cbind(a=runif(5),b=runif(5)))
myDF
N=2
a.order<-rev(order(myDF$a))[1:N]
b.order<-rev(order(myDF$b))[1:N]
myDF.max2a<-myDF[a.order,]
myDF.max2a
myDF.max2b<-m
Hi,
I use the max function often to find the top value from a matrix or
column of a data.frame.
Now I'm looking to find the top 2 (or three) values from my data.
I know that I could sort the list and then access the first two items,
but that seems like the "long way". Is there some way to a
6 matches
Mail list logo