R/misc.utilities.R
ult.RdExtract or replace the ultimate (last) element of a vector or a list, or an element counting from the end.
ult(x, i = 1L)
ult(x, i = 1L) <- valueAn element of x.
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.
x <- 1:5
(last <- ult(x))
#> [1] 5
(penultimate <- ult(x, 2)) # 2nd last.
#> [1] 4
(ult(x) <- 6)
#> [1] 6
(ult(x, 2) <- 7) # 2nd last.
#> [1] 7
x
#> [1] 1 2 3 7 6