0

one of my variables ranges from 1 to 5, the others from 0 to 10. For the ease of interpretation and comparison, i need to transform the scale of my variable so that all of them range from 0 to 10. How can rescale 1-5 to 0-10?

markus
  • 25,843
  • 5
  • 39
  • 58
Sean Burgess
  • 67
  • 1
  • 5

1 Answers1

2

We could use a linear transformation of the form f(x) = a + b * x.

Here is a reproducible example using some random sample data:

set.seed(2018)
x1 <- sample(1:5, 10, replace = T)
x2 <- sample(1:10, 10, replace = T)

f <- function(x) round(-5/2 + 5/2 * x)

f(x1)
#[1]  2  5  0  0  5  2  8  0 10  5

In fact, we can define a more general function that allows for arbitrary ranges of two variables, and that converts a score given range1 to a score with range2

f <- function(x, range1 = c(1, 5), range2 = c(0, 10)) {
    b <- (range2[2] - range2[1]) / (range1[2] - range1[1])
    a <- range2[2] - b * range1[2]
    return(round(a + b * x))
}
f(x1)
# [1]  2  5  0  0  5  2  8  0 10  5

You can change range1 and range2 as necessary.

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68