View source: R/formula.utilities.R
ult<- | R Documentation |
Extract or replace the *ult*imate (last) element of a vector or a list, or an element counting from the end.
ult(x, i = 1L) <- value
ult(x, i = 1L)
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 'i'th element from the end. |
An 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 <- c(1:5))
(ult(x) <- 6)
(ult(x, 2) <- 7) # 2nd last.
x
x <- 1:5
(last <- ult(x))
(penultimate <- ult(x, 2)) # 2nd last.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.