Considering a vector of numbers N scaled into a new vector V, what steps would be required to “unscale” the data?
Just do the inverse of what you did to scale the data, e.g. scale()
subtracts the mean and divides by the sd. So you would add the mean and multiply by sd.
It's always been frustrating to me that there's no base function to unscale. If you look at the attributes of a scaled vector, the center and scale are stored in the object, so it seems like it should be possible.
Hi, thanks for your answer!
Just to make it clearer, if this is the case:
x <- c (1, 2, 3, 4)
m <- mean(x)
sd <- sd(x)
scaled_x <- scale (x, center = TRUE, scale = TRUE)
To unscale the data, I have to do the following:
unscaled_x <- (scaled_x - m)*sd ?
Thanks!
almost:
x <- c (1, 2, 3, 4)
m <- mean(x)
sd <- sd(x)
scaled_x <- scale (x, center = TRUE, scale = TRUE)
unscaled_x <- (scaled_x * sd) + m
unscaled_x
#> [,1]
#> [1,] 1
#> [2,] 2
#> [3,] 3
#> [4,] 4
#> attr(,"scaled:center")
#> [1] 2.5
#> attr(,"scaled:scale")
#> [1] 1.290994
Created on 2022-03-07 by the reprex package (v2.0.1)
Thanks a lot for your help!
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.