Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

ult

Extract or replace the ultimate (last) element of a vector or a list, or an element counting from the end.


Description

Extract or replace the ultimate (last) element of a vector or a list, or an element counting from the end.

Usage

ult(x, i = 1L)

ult(x, i = 1L) <- value

Arguments

x

a vector or a list.

i

index from the end of the list to extract or replace (where 1 is the last element, 2 is the penultimate element, etc.).

value

Replacement value for the ith element from the end.

Value

An element of x.

Note

Due to the way in which assigning to a function is implemented in R, ult(x) <- e may be less efficient than x[[length(x)]] <- e.

Examples

x <- 1:5
(last <- ult(x))
(penultimate <- ult(x, 2)) # 2nd last.



(ult(x) <- 6)
(ult(x, 2) <- 7) # 2nd last.
x

statnet.common

Common R Scripts and Utilities Used by the Statnet Project Software

v4.4.1
GPL-3 + file LICENSE
Authors
Pavel N. Krivitsky [aut, cre] (<https://orcid.org/0000-0002-9101-3362>), Skye Bender-deMoll [ctb]
Initial release
2020-10-03

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.