0

I have a data set that shows the score from -2 to 2 for each shop.

df <- tribble(
       ~shop,      ~score_1,  ~score_2, ~score_3, 
       "A",             -2,      1,       -1.6,
       "",            -1.8,      1.5,      1.3,
       "C",            1.4,     -1.3,      0.6,
       "D",            0.3,      2,        1.9,
       "E",            0.5,     -1.7,     -1.5,
)

However, I'd like to rescale these scores from [-2, 2] to [0, 100].

What could be the way to do this?

datazang
  • 989
  • 1
  • 7
  • 20
  • 2
    relevant: https://stackoverflow.com/questions/5468280/scale-a-series-between-two-points ; https://stackoverflow.com/questions/15468866/scaling-a-numeric-matrix-in-r-with-values-0-to-1 – user20650 Jan 24 '22 at 20:46
  • 3
    You can use `scales::rescale`. With the `tidyverse`, you can convert them all with `mutate(df, across(-shop, .fns = scales::rescale, from = c(-2, 2), to = c(0, 100)))`. No answer because I'm assuming will be flagged as duplicate. – caldwellst Jan 24 '22 at 20:47
  • 1
    Why not just multiply by 25 and add 50? That way -2 -> 0, 0 -> 50, 1 -> 100 – Allan Cameron Jan 24 '22 at 21:05

0 Answers0