How to return 5 topmost values from vector in R?

pixel picture pixel · Sep 11, 2010 · Viewed 93.3k times · Source

I have a vector and I'm able to return highest and lowest value, but how to return 5 topmost values? Is there a simple one-line solution for this?

Answer

chrisamiller picture chrisamiller · Sep 11, 2010
> a <- c(1:100)
> tail(sort(a),5)
[1]  96  97  98  99 100