Extract the first, last, or nth value from a vector.

Note: These are simple wrappers around vctrs::vec_slice().

first.(x, default = NULL, na_rm = FALSE)

Arguments

x

A vector

default

The default value if the value doesn't exist.

na_rm

If TRUE ignores missing values.

Examples

vec <- letters

first(vec)
#> [1] "a"
last(vec)
#> [1] "z"
nth(vec, 4)
#> [1] "d"