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

View source: R/first-last-nth.R

firstR Documentation

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

Description

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

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

Usage

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

last(x, default = NULL, na_rm = FALSE)

nth(x, n, 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.

n

For nth(), a number specifying the position to grab.

Examples

vec <- letters

first(vec)
last(vec)
nth(vec, 4)

tidytable documentation built on Oct. 5, 2023, 5:07 p.m.