sortEnds: Select the Top-n Highest or Lowest Values in a Vector

Description Usage Arguments Value Note Author(s) Examples

View source: R/sortEnds.R

Description

Takes "n" values from the head or tail of a sorted vector. Utilizes the "partial" argument from sort for increased efficiency.

Usage

1
sortEnds(invec, n, where = "head")

Arguments

invec

The input vector

n

The number of values desired

where

Either "head" or "tail".

Value

A sorted vector of length = n

Note

The "tail" approach may not be consideraby faster than the standard approach.

Author(s)

Ananda Mahto

Examples

1
2
3
4
5
6
7
8
set.seed(1)
x <- sample(300, 45, TRUE)
sortEnds(x, 3)
sortEnds(x, 3, "tail")

## Compare with
head(sort(x), 3)
tail(sort(x), 3)

mrdwab/SOfun documentation built on June 20, 2020, 6:15 p.m.