Learn R Programming

statnet.common (version 4.10.0)

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

Value

An element of x.

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.

Examples

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

# \dontshow{
stopifnot(last==5)
stopifnot(penultimate==4)
# }

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

# \dontshow{
stopifnot(all(x == c(1:3, 7L, 6L)))
# }

Run the code above in your browser using DataLab