Learn R Programming

nandb (version 0.2.1)

Closest: What's the closest value in a vector?

Description

Given a number x and a numeric vector vec, what's the closest value to x in vec?

Usage

Closest(x, vec, index = FALSE)

Arguments

x

A number.

vec

A numeric vector.

index

If set to TRUE, return the index (rather than the value) of the closest element.

Value

A number.

Examples

Run this code
# NOT RUN {
Closest(pi, 0:10)
Closest(pi, 0:10, index = TRUE)

# }

Run the code above in your browser using DataLab