Skip to content

Rescale vector to have specified minimum, midpoint, and maximum

Usage

rescale_mid(x, to, from, mid, ...)

# S3 method for class 'numeric'
rescale_mid(x, to = c(0, 1), from = range(x, na.rm = TRUE), mid = 0, ...)

# S3 method for class 'logical'
rescale_mid(x, to = c(0, 1), from = range(x, na.rm = TRUE), mid = 0, ...)

# S3 method for class 'dist'
rescale_mid(x, to = c(0, 1), from = range(x, na.rm = TRUE), mid = 0, ...)

# S3 method for class 'POSIXt'
rescale_mid(x, to = c(0, 1), from = range(x, na.rm = TRUE), mid, ...)

# S3 method for class 'Date'
rescale_mid(x, to = c(0, 1), from = range(x, na.rm = TRUE), mid, ...)

# S3 method for class 'integer64'
rescale_mid(x, to = c(0, 1), from = range(x, na.rm = TRUE), mid = 0, ...)

# S3 method for class 'AsIs'
rescale_mid(x, to, from, ...)

Arguments

x

vector of values to manipulate.

to

output range (numeric vector of length two)

from

input range (vector of length two). If not given, is calculated from the range of x

mid

mid-point of input range

...

other arguments passed on to methods

Details

Objects of class <AsIs> are returned unaltered.

Examples

rescale_mid(1:100, mid = 50.5)
#>   [1] 0.00000000 0.01010101 0.02020202 0.03030303 0.04040404 0.05050505
#>   [7] 0.06060606 0.07070707 0.08080808 0.09090909 0.10101010 0.11111111
#>  [13] 0.12121212 0.13131313 0.14141414 0.15151515 0.16161616 0.17171717
#>  [19] 0.18181818 0.19191919 0.20202020 0.21212121 0.22222222 0.23232323
#>  [25] 0.24242424 0.25252525 0.26262626 0.27272727 0.28282828 0.29292929
#>  [31] 0.30303030 0.31313131 0.32323232 0.33333333 0.34343434 0.35353535
#>  [37] 0.36363636 0.37373737 0.38383838 0.39393939 0.40404040 0.41414141
#>  [43] 0.42424242 0.43434343 0.44444444 0.45454545 0.46464646 0.47474747
#>  [49] 0.48484848 0.49494949 0.50505051 0.51515152 0.52525253 0.53535354
#>  [55] 0.54545455 0.55555556 0.56565657 0.57575758 0.58585859 0.59595960
#>  [61] 0.60606061 0.61616162 0.62626263 0.63636364 0.64646465 0.65656566
#>  [67] 0.66666667 0.67676768 0.68686869 0.69696970 0.70707071 0.71717172
#>  [73] 0.72727273 0.73737374 0.74747475 0.75757576 0.76767677 0.77777778
#>  [79] 0.78787879 0.79797980 0.80808081 0.81818182 0.82828283 0.83838384
#>  [85] 0.84848485 0.85858586 0.86868687 0.87878788 0.88888889 0.89898990
#>  [91] 0.90909091 0.91919192 0.92929293 0.93939394 0.94949495 0.95959596
#>  [97] 0.96969697 0.97979798 0.98989899 1.00000000
rescale_mid(runif(50), mid = 0.5)
#>  [1] 0.0161502545 0.1332311077 0.8664583930 0.2033757852 0.2004404969
#>  [6] 0.0238313205 0.9599290915 0.2362372190 0.7907009264 0.2810220225
#> [11] 0.8881470385 0.2887909275 1.0000000000 0.5928984858 0.7679883783
#> [16] 0.8475260042 0.7717742081 0.4144511619 0.1257433910 0.0665635854
#> [21] 0.6612972385 0.6054793165 0.6623449638 0.3235016883 0.9958107811
#> [26] 0.7225179181 0.8853264986 0.9997501052 0.2089739211 0.6701359034
#> [31] 0.3858012835 0.0305971997 0.6208980503 0.6018302169 0.4036799634
#> [36] 0.8705370429 0.5182836151 0.9956238106 0.0005595317 0.6793575095
#> [41] 0.3668838124 0.9322530215 0.6840421328 0.6707795067 0.7647648747
#> [46] 0.5442966948 0.2304051687 0.5091965925 0.4144454177 0.7346814140
rescale_mid(1)
#> [1] 0.5