vec_rescale: Rescale vector to have a specified minimum and maximum

Description Usage Arguments Details Value Examples

View source: R/rescaling.R

Description

Mimicking rescale, but more type stable.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
vec_rescale(x, to, from, ...)

## Default S3 method:
vec_rescale(x, to = c(0, 1), from = range(x, na.rm = TRUE, finite = TRUE), ...)

## Default S3 method:
vec_rescale.default(
  x,
  to = c(0, 1),
  from = range(x, na.rm = TRUE, finite = TRUE),
  ...
)

Arguments

x

A vector to manipulate

to

An output range

from

The input range

...

Possible other arguments to downstream functions

Details

The default method should in theory be type stable as long as x can be cast without loss as numeric and vice versa and has a type stable range function. Will throw an error upon lossy casts, unless wrapped in vctrs::allow_lossy_cast.

Value

A vector of the same length as x

Examples

1
2
3
# Note that 1:10 returns integers, not doubles
vec_rescale(as.numeric(1:10))
vctrs::allow_lossy_cast(vec_rescale(1:10))

teunbrand/ggvctrcoords documentation built on Jan. 12, 2020, 6:25 p.m.