kris - 4 years ago 88
R Question

# how can i denormalization the data of a dataframe

I have tried following one for normalization of a dataframe. I have problem in denormalising dataframe.
how to denormalize it.

``````      form <- function(x) {(x - min(x, na.rm=TRUE))/(max(x,na.rm=TRUE) -
min(x, na.rm=TRUE))}
normed <- as.data.frame(lapply(m1, form))
``````

dataset

``````      'data.frame': 96611 obs. of  10 variables:
\$ Timestamp       : num  1388619000 1388619900 1388620800 1388621700    1388622600 ...
\$ avg.price       : num  -14.55 -10.73 0.65 0.62 0.18 ...
\$ weekday         : num  4 4 5 5 5 5 5 5 5 5 ...
\$ total.energy    : num  0.76 0.18 330.56 1.75 1.62 ...
\$ O.avgprice      : num  -10.17 -13.79 -2.64 -9.77 -2.96 ...
\$ O.firstquartil  : num  -20 -24.25 -5.42 -13.74 -4.45 ...
\$ O.thirdquartil  : num  -3.29 -6.78 -1.3 -0.19 -2.2 0 5 -1.92 0.22 5.08 ...
``````

Why don't you just invert your formula? If normalization used

``````(x - min(x, na.rm=TRUE))/(max(x,na.rm=TRUE) - min(x, na.rm=TRUE))
``````

use

``````(x * (max(y, na.rm=TRUE) - min(y, na.rm=TRUE)) + min(y, na.rm=TRUE))
``````

for denormalization, with `y` refering to your original data before normalization.

Working example:

``````test <- list(c(1,5,6,7,10), c(2,4,6,6,12))
> test
[[1]]
[1]  1  5  6  7 10

[[2]]
[1]  2  4  6  6 12

testnorm <- lapply(test, function(x) (x-min(x))/(max(x)-min(x)))
> testnorm
[[1]]
[1] 0.0000000 0.4444444 0.5555556 0.6666667 1.0000000

[[2]]
[1] 0.0 0.2 0.4 0.4 1.0

testdenorm <- mapply(function(x, y) (x*(max(y)-min(y)))+min(y), testnorm, test)
> testdenorm
[,1] [,2]
[1,]    1    2
[2,]    5    4
[3,]    6    6
[4,]    7    6
[5,]   10   12
``````

Make sure you use the `min()` and `max()`-values of your original data. If you do not have those, I'm afraid you're out of luck.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download