frange: Fast implementation of range.

Description Usage Arguments Value Examples

View source: R/frange.R

Description

This is an efficient C++ implementation of range for numeric vectors: it avoids S3 dispatch, and computes both min and max in a single pass through the input.

Usage

1

Arguments

x

A numeric vector, or an S3 object built on top of integer and double atomic vectors, as long as there is a method for restore().

finite

If TRUE ignores missing values and infinities. Note that if the vector is empty, or only contains missing values, frange will return c(Inf, -Inf) because those are the identity values for min and max respectively.

Value

A numeric vector of length two. If x contains no non-missing values, this will be c(Inf, -Inf).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# frange() always ignores missing values
frange(c(1:10, NA))

# frange() works with dates and times
frange(Sys.Date())
frange(Sys.time())

# frange() is much faster than range()
x <- runif(1e6)
system.time(range(x))
system.time(frange(x))

hadley/ggstat documentation built on May 17, 2019, 10:40 a.m.