Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rescale with a vector of 0 #401

Closed
BioinformaNicks opened this issue Oct 24, 2023 · 1 comment
Closed

Rescale with a vector of 0 #401

BioinformaNicks opened this issue Oct 24, 2023 · 1 comment

Comments

@BioinformaNicks
Copy link

Hi,

Is it the intended behaviour that the rescale function does the following?
rescale(c(0,0,0,0), to = c(0,100))
[1] 50 50 50 50

Wouldn't it be more logical to still have a zero stay zero?

@teunbrand
Copy link
Contributor

It seems very much by design that if from has no/zero range, the result has mean(to) as value.

scales:::rescale.numeric
#> function (x, to = c(0, 1), from = range(x, na.rm = TRUE, finite = TRUE), 
#>     ...) 
#> {
#>     if (zero_range(from) || zero_range(to)) {
#>         return(ifelse(is.na(x), NA, mean(to)))
#>     }
#>     (x - from[1])/diff(from) * diff(to) + to[1]
#> }
#> <bytecode: 0x000001d3024e1bc0>
#> <environment: namespace:scales>

Created on 2023-10-24 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants