Skip to contents

Employs min() and max(). However, base::range(), there is no argument for removing Inf values.

Usage

range2(x, na.rm = FALSE)

Arguments

x

A numeric (or character) vector (see Note in base::min)

na.rm

Logical, if TRUE removes missing values

Value

A numeric vector of length 2 of the minimum and maximum values, respectively

Examples

# \donttest{
x <- rep(1:1e5, 100)
system.time(rep(range(x),  100))
#>    user  system elapsed 
#>   0.025   0.008   0.033 
system.time(rep(range2(x), 100))
#>    user  system elapsed 
#>   0.019   0.000   0.018 
x[sample(x, 1e5)] <- NA

system.time(rep(range(x, na.rm = TRUE), 100))
#>    user  system elapsed 
#>   0.295   0.040   0.335 
system.time(rep(range2(x, na.rm = TRUE), 100))
#>    user  system elapsed 
#>   0.020   0.000   0.019 
# }