Description Usage Arguments Value Examples
The base R function range
returns the minimum and maximum
of a vector, but the "range" is actually defined as the difference between
the minimum and maximum. This function calculates the actual range. It is
equivalent to the base R code diff(range(x))
, but a bit simpler and
much faster.
1 |
x |
Integer or numeric vector. |
integer |
Logical value for whether |
Integer or numeric value.
1 2 3 4 5 6 7 8 9 | # truerange vs. diff(range()) for integer vector
x <- rpois(1000, lambda = 5)
all.equal(diff(range(x)), truerange(x, TRUE))
benchmark(diff(range(x)), truerange(x, TRUE), replications = 2000)
# truerange vs. diff(range()) for numeric vector
x <- rnorm(1000)
all.equal(diff(range(x)), truerange(x))
benchmark(diff(range(x)), truerange(x), replications = 2000)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.