As introduce in the title, I would like to select the 10% highest and the 10% lowest values from a vector. How can I manage to do that?
Anyone can help me ? Thanks a lot
This is an example that takes roughly 10%:
v <- rnorm(100)
sort(v)[1:(length(v)/10)] # lowest, in increasing order.
sort(v, decreasing=TRUE)[1:(length(v)/10)] # highest, in decreasing order.
This will return a vector containing the bottom and top 10% of x:
> set.seed(123)
> x<-rnorm(100)
> x[{q<-rank(x)/length(x);q<0.1 | q>=0.9}]
[1] 1.558708 1.715065 -1.265061 1.786913 -1.966617 -1.686693 -1.138137
[8] 1.253815 -1.265396 2.168956 -1.123109 1.368602 1.516471 -1.548753
[15] 2.050085 -2.309169 -1.220718 1.360652 2.187333 1.532611
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With