nth: Extract the nth value from a vector

View source: R/nth.R

nthR Documentation

Extract the nth value from a vector

Description

nth get the value from a vector with its position, while maxth and minth get the nth highest or lowest value from the vector.

Usage

nth(v, n = 1)

maxth(v, n = 1)

minth(v, n = 1)

Arguments

v

A vector

n

Fornth, a single integer specifying the position. Default uses 1. Negative integers index from the end (i.e. -1L will return the last value in the vector). If a double is supplied, it will be silently truncated. For maxth and minth, a single integer indicating the nth highest or lowest value.

Value

A single value.

References

https://stackoverflow.com/questions/2453326/fastest-way-to-find-second-third-highest-lowest-value-in-vector-or-column/66367996#66367996

Examples


x = 1:10
nth(x, 1)
nth(x, 5)
nth(x, -2)

y = c(10,3,4,5,2,1,6,9,7,8)
maxth(y,3)
minth(y,3)


hope-data-science/tidyfst documentation built on Sept. 23, 2024, 8:05 p.m.