last_elem: Last element of a vector

View source: R/utils.R

last_elemR Documentation

Last element of a vector

Description

Returns the last element of the given vector in the most efficient way.

Usage

last_elem(x)

Arguments

x

Vector.

Details

The last element is obtained using x[length(x)], which is done in O(1) and faster than, for example, any of Rcpp::mylast(x), tail(x, n=1), dplyr::last(x), ⁠x[end(x)[1]]]⁠, and rev(x)[1].

Value

The last element in the vector x.

Examples

last_elem(c(2, 6, 1, 4))

EQRN documentation built on April 4, 2025, 12:45 a.m.