absolute.min: Absolute Minimum

Description Usage Arguments Value Examples

View source: R/util.R

Description

Returns the signed value of the element with the minimum absolute value in a vector.

Usage

1

Arguments

x

Numeric vector (NAs are allowed)

Value

A single value; the value with the smallest absolute value, but with its original sign. This is equivalent to (and implemented as) x[which.min(abs(x))]

The value is NA if x has no non-NA values (c.f. which.min).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
set.seed(1)
x <- rnorm(16)
min(x)          # -2.2147
min(abs(x))     #  0.0444
absolute.min(x) # -0.0444: preserves sign

# NA values OK:
absolute.min(c(-1, 4, NA))

# Slightly unintuitive behaviour:
absolute.min(numeric(0)) # numeric(0)
absolute.min(NA)         # NA

richfitz/TRAMPR documentation built on May 25, 2017, 2:07 a.m.