Description Usage Arguments Value See Also Examples
Pick the top n
values from the head or tail of a vector.
1 2 3 |
x |
An atomic vector. |
n |
A single integer. Doubles are silently coerced to integer. |
top()
returns a vector of the same type as the input.
in_top()
returns a logical vector.
Other general functions to pick or drop rows of a dataframe: pick_recensus
,
pick_top
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.