nth {dplyr} | R Documentation |
These are straightforward wrappers around [[
. The main
advantage is that you can provide an optional secondary vector that defines
the ordering, and provide a default value to use when the input is shorter
than expected.
nth(x, n, order_by = NULL, default = default_missing(x)) first(x, order_by = NULL, default = default_missing(x)) last(x, order_by = NULL, default = default_missing(x))
x |
A vector |
n |
For |
order_by |
An optional vector used to determine the order |
default |
A default value to use if the position does not exist in
the input. This is guessed by default for atomic vectors, where a
missing value of the appropriate type is return, and for lists, where
a |
A single value. [[
is used to do the subsetting.
x <- 1:10 y <- 10:1 last(x) last(x, y)