last_elem | R Documentation |
Returns the last element of the given vector in the most efficient way.
last_elem(x)
x |
Vector. |
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]
.
The last element in the vector x
.
last_elem(c(2, 6, 1, 4))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.