Using R, I am trying to min-max normalize a column, but instead of using the min and max of all the column values, I need to set min and max by groups that are determined by another column.
Please see this example:
x <- c(0, 0.5, 1, 2.5, 0.2, 0.3, 0.5, 0,0,0.1, 0.7)
y <- c(1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3)
df <- data.frame (x, y)
df
For y=1, min(x) = 0, and max(x) = 2.5. For y=2, min(x) = 0.2, and max(x) = 0.5, and so forth.
Based on this grouped min and max, normalization is performed.
I found a similar question for Python, but it didnt help me much: Normalize a column of dataframe using min max normalization based on groupby of another column