Learn R Programming

tidyft (version 0.9.20)

nth: Extract the nth value from a vector

Description

Get the value from a vector with its position.

Usage

nth(v, n = 1)

Value

A single value.

Arguments

v

A vector

n

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.

Examples

Run this code

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

Run the code above in your browser using DataLab