range2: Range 2

Description Usage Arguments Value Examples

View source: R/stats.R

Description

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

Usage

1
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

1
2
3
4
5
6
7
x <- rep(1:1e5, 100)
system.time(rep(range(x),  100))
system.time(rep(range2(x), 100))
x[sample(x, 1e5)] <- NA

system.time(rep(range(x, na.rm = TRUE), 100))
system.time(rep(range2(x, na.rm = TRUE), 100))

mark documentation built on July 16, 2021, 9:07 a.m.