VOOZH about

URL: https://www.geeksforgeeks.org/r-language/transform-the-scaled-matrix-to-its-original-form-in-r-programming-using-matrix-computations/

⇱ Transform the Scaled Matrix to its Original Form in R Programming - Using Matrix Computations - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Transform the Scaled Matrix to its Original Form in R Programming - Using Matrix Computations

Last Updated : 15 Jul, 2025
In R programming, a matrix can be scaled and centered using scale() function. But, there is no in-built function to transform the scaled matrix back to the original matrix. In this article, we'll learn to transform the scaled matrix back to the original matrix using some simple computations.

Using Matrix Attributes

Attributes of the scaled matrix can be used to unscale the matrix back to its original matrix. Output:
Original matrix:
 [, 1] [, 2] [, 3] [, 4] [, 5]
[1, ] 1 5 9 13 17
[2, ] 2 6 10 14 18
[3, ] 3 7 11 15 19
[4, ] 4 8 12 16 20
Scaled matrix:
 [, 1] [, 2] [, 3] [, 4] [, 5]
[1, ] -1.1618950 -1.1618950 -1.1618950 -1.1618950 -1.1618950
[2, ] -0.3872983 -0.3872983 -0.3872983 -0.3872983 -0.3872983
[3, ] 0.3872983 0.3872983 0.3872983 0.3872983 0.3872983
[4, ] 1.1618950 1.1618950 1.1618950 1.1618950 1.1618950
attr(, "scaled:center")
[1] 2.5 6.5 10.5 14.5 18.5
attr(, "scaled:scale")
[1] 1.290994 1.290994 1.290994 1.290994 1.290994
Unscaled matrix:
 [, 1] [, 2] [, 3] [, 4] [, 5]
[1, ] 1 5 9 13 17
[2, ] 2 6 10 14 18
[3, ] 3 7 11 15 19
[4, ] 4 8 12 16 20

Using Mean and Standard Deviation

In this example, we'll unscale the scaled matrix using mean and standard deviation of the original matrix.

Output:

Original matrix:
 a b
[1, ] 5.552301 1.9865159
[2, ] 3.936486 17.5327829
[3, ] 5.379720 15.0981877
[4, ] 3.546333 0.5230305
[5, ] 5.043194 2.0930855

Scaled matrix:
 a b
[1, ] 0.01543556 -2.062174
[2, ] -0.69057233 5.252016
[3, ] -0.05997146 4.106591
[4, ] -0.86104456 -2.750713
[5, ] -0.20701146 -2.012036
attr(, "scaled:center")
 a b 
5.516974 6.369655 
attr(, "scaled:scale")
 a b 
2.288663 2.125494 

Unscaled matrix:
 a b
[1, ] 5.552301 1.9865159
[2, ] 3.936486 17.5327829
[3, ] 5.379720 15.0981877
[4, ] 3.546333 0.5230305
[5, ] 5.043194 2.0930855
attr(, "scaled:center")
 a b 
5.516974 6.369655 
attr(, "scaled:scale")
 a b 
2.288663 2.125494 
Comment
Article Tags:

Explore