Normalization by maximum value in R

I have the following dataframe:

``````df<-structure(list(Number = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), Production = c(239.936,
422.18352, 5.863376, 23.9936, 406.09168, 143.9616, 42.348704,
61.67968, 12.956544, 182.058268), Consumption = c(467.366666666667,
795.2, 176.2, 467.366666666667, 738.5, 2226.36666666667, 107.133333333333,
198.633333333333, 210.3, 1198.96666666667)), row.names = c(NA,
10L), class = "data.frame")

> df
Number Production Consumption
1       1 239.936000    467.3667
2       2 422.183520    795.2000
3       3   5.863376    176.2000
4       4  23.993600    467.3667
5       5 406.091680    738.5000
6       6 143.961600   2226.3667
7       7  42.348704    107.1333
8       8  61.679680    198.6333
9       9  12.956544    210.3000
10     10 182.058268   1198.9667
``````

So, I'm generating a weight variable, which considers the division of two distinct measures, as below:

``````Weight = Production(m³/day)/Consumption(kWh/day)
``````

So, I need to normalize these two metrics to calculate the weight vector, so I use the division by the maximum value, doing it like this:

``````df\$Weight<-(df\$Production/max(df\$Production))*(max(df\$`Consumption`)/df\$`Consumption`)

> df
Number Production Consumption    Weight
1       1 239.936000    467.3667 2.7072795
2       2 422.183520    795.2000 2.7997569
3       3   5.863376    176.2000 0.1754839
4       4  23.993600    467.3667 0.2707279
5       5 406.091680    738.5000 2.8998064
6       6 143.961600   2226.3667 0.3409929
7       7  42.348704    107.1333 2.0845433
8       8  61.679680    198.6333 1.6375154
9       9  12.956544    210.3000 0.3248967
10     10 182.058268   1198.9667 0.8007533
``````

Therefore, I would like to know if the code I made is correct and also if this can be considered a normalization, the division by the maximum?

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.