in_top: Pick the top 'n' values from the head or tail of a vector.

Description Usage Arguments Value See Also Examples

Description

Pick the top n values from the head or tail of a vector.

Usage

1
2
3
in_top(x, n = 1L)

top(x, n = 1L)

Arguments

x

An atomic vector.

n

A single integer. Doubles are silently coerced to integer.

Value

See Also

Other general functions to pick or drop rows of a dataframe: pick_recensus, pick_top

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Pick from the head
top(1:3)
# Same
top(1:3, 1L)

# Pick from the tail
top(1:3, -2L)

# Useful for filtering
in_top(1:3)
in_top(1:3, -1L)

subset(mtcars, in_top(cyl))

subset(mtcars, in_top(cyl) & in_top(carb))

subset(mtcars, in_top(cyl, -2L))

# Careful: Remember that `FALSE` evaluates to 0
lgl <- c(TRUE, FALSE, TRUE)
int <- as.integer(lgl)
int

top(lgl)
top(int)

top(lgl, -1)
top(int, -1)

forestgeo/fgeo.misc documentation built on June 23, 2019, 6:26 p.m.