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
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))
If a double is supplied, it will be silently truncated.
An optional vector used to determine the order
A default value to use if the position does not exist in the input. This is guessed by default for
base vectors, where a missing value of the appropriate type is returned, and for lists, where a
For more complicated objects, you'll need to supply this value. Make sure it is the same type as
A single value.
[[ is used to do the subsetting.
x <- 1:10 y <- 10:1 first(x)#>  1last(y)#>  1nth(x, 1)#>  1nth(x, 5)#>  5nth(x, -2)#>  9nth(x, 11)#>  NAlast(x)#>  10# Second argument provides optional ordering last(x, y)#>  1# These functions always return a single value first(integer())#>  NA