-5

I have tried to find this solution but everywhere solution is given for normalization of whole dataset.

I have a data frame

df
M   T   N    T
123 35  453  34
169 119 135  239
728 435 613  787
115 748 5459 13277
762 382 823  919
986 963 883  348
591 892 375  818
278 21  777  455

I want to apply normalization to only one column i.e. "N"

Normalization formula = (x-min)/(max-min)

The new datafarme should be like:

    nm
 M  T     N      T
123 35  0.0596  34
169 119 0.0000  239
728 435 0.0897  787
115 748 1.0000  13277
762 382 0.1291  919
986 963 0.1404  348
591 892 0.0450  818
278 21  0.1205  455

Kindly provide the solution.

Thanks!!

ROY
  • 268
  • 2
  • 11

1 Answers1

2
df <- transform(df, N = (df$N - min(df$N)) / (max(df$N) - min(df$N))

or as @jogo commented:

df <- transform(df, N = (N - min(N)) / (max(N) - min(N))
George
  • 5,808
  • 15
  • 83
  • 160